如何确保版权声明陪我所有的源文件为Java的Maven构建?
-
10-07-2019 - |
题
有没有人强制执行他们的Java版权声明纳入一种标准方法/ Maven的建立?我意识到,因为产品本身是复制书面和,如果有人有我的消息来源我有更大的问题,它不应该是必要的,但我被要求检查并想知道如果的CheckStyle,PMD还是其他什么东西自动处理这
是否有一个工具,其处理用于版权检查?
解决方案
Yes, Checkstyle (and the maven-checkstyle-plugin) can do that, it can check that every source files do contain a license header. Put that header in a text file and use the headerLocation
to point on it (it uses by default LICENSE.txt
).
Let's say you want to use checkstyle.license
for your copyright notices. For a multi-modules build, the standard approach is to create a dedicated module to host Checkstyle resources (see Multimodule configuration):
whizbang
|-- pom.xml
|-- build-tools
| |-- src
| | `-- main
| | `-- resources
| | `-- whizbang
| | |-- checkstyle.xml
| | `-- checkstyle.license
| `-- pom.xml
|-- core
|-- gui
|-- jmx
`-- src
Then, include the Checkstyle configuration in the top level pom.xml
.
<pluginManagement>
<plugins>
<!-- Apply checkstyle rules and fail the build in case of errors. The
checkstyle config files are taken from the build-tools JAR module.-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>2.4</version>
<dependencies>
<dependency>
<groupId>com.example.whizbang</groupId>
<artifactId>build-tools</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>whizbang/checkstyle.xml</configLocation>
<headerLocation>whizbang/checkstyle.license</headerLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</pluginManagement>
This setup will ensure that a copyright header is present in source files (and apply other Checkstyle rules but this is another story). Adapt it to suit your needs.
其他提示
I just found http://code.google.com/p/maven-license-plugin/ seems reasonable too