How do I make gradle's build task generate the shadow jar _instead_ of the "regular" jar?

17.5k Views Asked by At

(this is using gradle 2.4)

For one of my projects, split into several submodules, I use the shadow plugin which works very well for my needs; it has a main, and as recommended by the plugin's README, I use the application plugin in conjuction with it so that the Main-Class is generated in the manifest, all works well.

Now, this is a SonarQube plugin project, and I also use (successfully!) the gradle sonar packagin plugin. And what this plugin does is, when you ./gradlew build, generate the sonar plugin instead of the "regular" jar.

I wish to do the same for my subproject here, except that I want it to generate only the shadow jar plugin instead of the "regular" plugin... Right now I generate both using this simple file:

buildscript {
    repositories {
        jcenter();
    }
    dependencies {
        classpath(group: "com.github.jengelman.gradle.plugins",
            name:"shadow", version:"1.2.1");
    }
}

apply(plugin: "application");
apply(plugin: "com.github.johnrengelman.shadow");

dependencies {
    // whatever
}

mainClassName = //whatever

artifacts {
    shadowJar;
}

// Here is the hack...

build.dependsOn(shadowJar);

How do I modify this file so that only the shadow jar is generated and not the regular jar?

1

There are 1 best solutions below

3
On

You could disable the jar task by adding the following lines to your gradle script:

// Disable the 'jar' task
jar.enabled = false

So, when executing the gradle script, it will show

:jar SKIPPED

If you wish to configure all sub-projects, then you can add the following into your root build.gradle

subprojects {

    // Disable the 'jar' task
    tasks.jar.enabled = false

}