2

Is there a standard way people enforce the inclusion of copyright notices in their java/maven builds? I realize that it shouldn't be necessary since the product itself is copy-written and if someone has my source I have much bigger problems, but I'm being asked to check and was wondering if checkstyle, PMD or something else handled this automatically.

Is there a tool which handles checking for copyright?

Linus Fernandes
  • 498
  • 5
  • 30
Peter Kahn
  • 12,364
  • 20
  • 77
  • 135

3 Answers3

2

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
2

I just found http://code.google.com/p/maven-license-plugin/ seems reasonable too

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

If your project is in a Git repository, you can follow the REUSE standard from the Free Software Foundation Europe. With the reuse-tool you can check REUSE compliance by executing reuse lint. For continuous integration (CI) you can use the fsfe/reuse Docker image.

traylor
  • 31
  • 4