14

(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?

fge
  • 119,121
  • 33
  • 254
  • 329
  • Better to use `assemble.dependsOn(shadowJar);` so that your tests also use the shadowJar. Refer to build pipeline PICTURE : https://docs.gradle.org/current/userguide/java_plugin.html – Zasz Aug 22 '15 at 14:13
  • This proved to be too much hassle because I kept getting unreliable results. After several hours of tweaking without getting anywhere I decided to completely refactor my project to not require fat jars instead. – Coder Guy Dec 16 '19 at 02:52

1 Answers1

13

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

}
MJSG
  • 1,035
  • 8
  • 12
  • Well, it is only for that particular project but hmm, indeed I don't need the jars for any project... – fge May 18 '15 at 17:54
  • @fge there is also an option to remove the task entirely, however you would have to ensure that all tasks that depend on the jar task have to be mapped (easier to disable it) – MJSG May 18 '15 at 18:02
  • OK, I'll try as soon as I get the time to do it but this approach looks very promising! Already upvoted, I'll keep you informed... – fge May 18 '15 at 18:10