How to declare a license for a Gradle project?


(Sebastian Schuberth) #1

Is there a canonical way to declare a license as part of Gradle build files, in a similar way how I can add a <licenses> tag to maven POMs? In particular, I’m looking for a solution that is independent of any Gradle plugins (like POM export), and that can be queried programmatically e.g. via the tooling API.

Of course, I could simply add a LICENSE net to my root build.gradle file. I was just wondering whether there is also some dedicated meta-data field for this, to e.g. put the concise SPDX identifier in, instead of having to parse the LICENSE file.


(Dimitar Dimitrov) #2

There are a number of plugins dealing with licenses: https://plugins.gradle.org/search?term=license

What do you want to do with this metadata? The simplest thing is to just add a property in your project’s gradle.properties or just put the license in a well-known file.


(Sebastian Schuberth) #3

I did the same search, but most of these deal with licenses of (transitive) dependencies.

Using “a property” is not standardized, i.e. WRT the name of the property. And like I said initially, of course I could put e.g. the Apache 2.0 license text into a LICENSE file. But that means I’d still need to use some tool (like https://github.com/benbalter/licensee) that is able to recognize the Apache 2.0 license text and output the SPDX identifier for it.

It would be much more convenient if there was a Gradle built-in property / API that is supposed to hold the SPDX identifier for the declared license that could be queried programmatically.


(Renato Athaydes) #4

I always add licenses to my projects which I publish on Maven Central as that’s mandatory… See how I do it here: https://github.com/renatoathaydes/rawhttp/blob/master/rawhttp-core/build.gradle#L72 for example. I believe this config is added by the Maven plugin, and the generated pom.xml will contain the expected licenses tag Maven repos expect.


(Sebastian Schuberth) #5

Any particular reason why you’re using the Maven plugin instead of the Maven-Publish plugin?


(Renato Athaydes) #6

The pom.xml looks correct with the maven plugin, but with maven-publish, last I tried, it looked broken and missed stuff. Is there any reason maven-publish should be used instead? I haven’t had problems with maven so far.


(Sebastian Schuberth) #7

I don’t know as I’ve used neither so far, but the maven-publish just looked more recent / like the successor of the maven plugin to me.