Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 956
fge Avatar asked May 18 '15 17:05

fge


People also ask

What is shadowJar in Gradle?

Shadow is a plugin that packages an application into an executable fat jar file if the current file is outdated. Tutorials → Working with JAR files → Fat JAR files. The task shadowJar (e.g., running the command gradlew shadowJar or gradlew clean shadowJar ) creates the JAR file in the build/libs folder.

Can't resolve all dependencies for configuration Gradle?

This is because of slow internet connection or you haven't configure proxy settings correctly. Gradle needs to download some dependencies , if it cant access the repository it fires this error. All you have to do is check your internet connection and make sure gradle can access the maven repository.

Where are Gradle dependencies defined?

The Gradle build pulls all dependencies down from the Maven Central repository, as defined by the repositories block.


1 Answers

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

}
like image 158
MJSG Avatar answered Oct 31 '22 19:10

MJSG