Help with Gradle's License Plugin

I am building the HyperQuest plugin atm at but I am having trouble with my Gradle build. I am 100% new to Gradle and I wanted to get the License pre-commit system Sponge has but I tried copying the build.gradle file sponge has and it failed. Could someone help me out? Thanks a lot, in advance.

PS: I posted this in Plugin Support. If this was incorrect please move it to the proper category. :smiley: Thanks.


Edit: i looked at your build.gradle.

You need to get the plugin as dependency first. So you need to add this to your buildscript section:

repositories {
dependencies { 
    classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'

Then add this: apply plugin: 'license'

Also, this here:

defaultTasks 'licenseFormat'

will make gradle run that task every time you use it automatically.

For license header formatting do this:

license {
    //the project name to use =
    //the organizations name etc
    ext.organization = project.organization
    ext.url = project.url
    ext.year = project.inceptionYear

    //for usage of these values see this:
    //files to exclude from formatting (anything that is a .info file and assets in this example)
    exclude "**/*.info"
    exclude "assets/**"
    //the file that contains the header
    header file('HEADER.txt')
    //the source sets to apply the license to
    //this should be enough for you, it covers all the projects source sets
    sourceSets = project.sourceSets
    ignoreFailures false
    strictCheck true
    //what style your comment should be
    mapping {
        //in this case it's the following: /* and then continuing with stars.
        java = 'SLASHSTAR_STYLE'

Further documentation of the license section can be found here: GitHub

Hope I could help you.

1 Like

lol. Sorry forgot to commit (done now). See when I run ./gradlew licenseFormat it just says UP-TO-DATE and no headers get added in the file. I have tried everything. :cry:

Edit: Wow I am very sorry you had to write all of this. I actually have most of what you did in the Gradle file. Still nothing… Just the “its uptodate man!” and no changes in files.

Could you commit your HEADER.txt

Edit: nevermind :stuck_out_tongue: It’ll be there for future reference at least. Gradle can sometimes be confusing

Done. Gradle is very confusing…
Edit: Thanks a lot for the help you are giving!

I think I may have forgotten the source sets. Was that important?

It should by default use all. What i’m ondering is wether your sourceSets contain anything… (at least from the scripts point of view)

How do I even set my source sets? I have not configured this at all. :stuck_out_tongue:

Gradle DSL Reference

Well clearly i’m an idiot…

Did that fix it? :stuck_out_tongue:

Wait so I need to specify my source set? The SpongeAPI doesn’t seem to have that. Im so confused.

Well, yes, the issue is in fact that you have not source sets or are not using them, if I build your project the jar only contains the META-INF and no compiled classes.

So, the problem was, that you had your source directory set up in a non conventional way (convention: src/main/java/yourpackageshere, yours: src/yourpackageshere). That non conventional setup requires adding the directory to the sourceSets specifically. I’d recomment that you go with just refactoring it to fith the convention.

Woooooops. Thanks a bunch! I guess conventions do matter. -.-