如何确保java maven构建的所有源文件都附带版权声明?

如何确保java maven构建的所有源文件都附带版权声明?,java,maven-2,checkstyle,copyright-display,Java,Maven 2,Checkstyle,Copyright Display,人们在java/maven构建中是否有标准的方式强制包含版权声明?我意识到这不应该是必要的,因为产品本身是拷贝编写的,如果有人有我的源代码,我会有更大的问题,但我被要求检查,想知道checkstyle、PMD或其他东西是否自动处理了这个问题 是否有一个工具可以检查版权?是的,,Checkstyle(和)可以做到这一点,它可以检查每个源文件是否包含许可证头。将该标题放在文本文件中,并使用指向该文件(默认情况下使用LICENSE.txt) 假设您想使用checkstyle.license作为版权声明

人们在java/maven构建中是否有标准的方式强制包含版权声明?我意识到这不应该是必要的,因为产品本身是拷贝编写的,如果有人有我的源代码,我会有更大的问题,但我被要求检查,想知道checkstyle、PMD或其他东西是否自动处理了这个问题


是否有一个工具可以检查版权?

是的,,Checkstyle(和)可以做到这一点,它可以检查每个源文件是否包含许可证头。将该标题放在文本文件中,并使用指向该文件(默认情况下使用
LICENSE.txt

假设您想使用
checkstyle.license
作为版权声明。对于多模块构建,标准方法是创建一个专用模块来承载Checkstyle资源(请参阅):

然后,在顶层
pom.xml
中包含Checkstyle

<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>

org.apache.maven.plugins
maven checkstyle插件
2.4
威兹邦
构建工具
1
真的
whizbang/checkstyle.xml
whizbang/checkstyle.license
检查
...
此设置将确保源文件中存在版权头(并应用其他Checkstyle规则,但这是另一回事)。调整它以适应您的需要。

我刚刚发现
似乎很合理,

如果你的项目在Git存储库中,你可以跟随来自自由软件基金会的欧洲。使用,您可以通过执行
REUSE lint
来检查重用合规性。对于连续集成(CI),可以使用Docker映像

<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>