Code Monkeyism

Programming is hard by Stephan Schmidt

@license and @copyright in Java 7 ?

Alex wrote in his latest Java 7 Roundup about my idea of a @license and Paul’s @copyright addendum. I wrote about the idea here.

@License(name = "Apache",version = "2.0")
@Copyright(owner = "Stephan Schmidt")
public class Example {
    public void doWhatever() { ... }
}

In the comments of that post Paul Hammant mentioned a @copyright annotation, which could help verify the copyright status of code. The best and easiest way to use @license and @copyright would be to add it at the package level. Few people know that Java got a package level construct called package-info.java where developers can add package level annotations:

“Typically package-info.java contains only a package declaration, preceded immediately by the annotations on the package.”

Hopefully such an annotation would be implemented as a Java standard and used by all major DI containers like Spring, Guice and Apache Composer, because as I wrote in the comments:

“A container could know about licenses and issue a warning when injecting incompatible stuff. This would make some managers in companies happy.”

As I want to pursue the idea further, it would be best to move this with a short JSR into Java 7.

About the author: Stephan Schmidt is currently a team manager at ImmobilienScout24 in Berlin. Stephan has been working as a head of development and CTO. He has used a lot of different technologies in the last 20 years including Java, Rails and Python. Stephans main field of interest is maintainablity and productivity in software development. Want to know more? All views are only his own.

If you did like this article but you don't want to subscribe to new articles with your reader, you can follow me on Twitter or subscribe to new posts with your email:

Comments

Stephen Colebourne

You should probably chat to JSR-305/JSR-308 first before thinking about a new JSR.

stephan

Thought about that, but it’s neither about defect prevention (JSR 305) nor about new places for annotations (JSR 308). But it should be a good idea to talk to the leads. Thanks.

Geoffrey Wiseman

I was thinking of an @License annotation the other day; what I’d really love is the ability to report on the @License of a project and its dependencies, and, ideally, establish some rules about it, and put that into a Maven plugin or something equally re-usable.

For instance, if you’re building a commercial application, you might want to exclude GPL dependencies, or generate a report that can be reviewed regularly to ensure that you meet some license compliance goals.

Leave a Reply