Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename shadow jar produced by shadow plugin to original artifact name

I am using gradle shadow plugin to build my uber jar.

build.grade file looks like:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
    }
}

apply plugin: 'com.github.johnrengelman.shadow'


dependencies {
   compile "com.amazonaws:aws-lambda-java-events:1.3.0"

}

assemble.dependsOn(shadowJar)

It produces following jars in build/libs folder.

myProject-1.0.0-SNAPSHOT.jar
myProject-1.0.0-SNAPSHOT-all.jar '//uber jar

I want to replace original jar with uber jar. How do i do this?

like image 917
user93796 Avatar asked Jan 05 '18 01:01

user93796


3 Answers

It isn't clear why want to do this, but I'm assuming you mean "with the original JAR's name". You should do 2 things:

  1. Give a different classifer to the jar task (or archiveName, or the other properties that affect the name) or disable it so that you don't constantly overwrite it on every build and avoid doing unnecessary work
  2. Change the classifier on the shadowJar task

The ShadowJar extends from the Gradle built-in Jar task, so most of the configuration options from that apply to the ShadowJar task.

tasks.jar.configure {
  classifier = 'default'
}

tasks.shadowJar.configure {
  classifier = null
}
like image 107
mkobit Avatar answered Nov 16 '22 07:11

mkobit


For least keystrokes, without burning any bridges,

replace the line:

assemble.dependsOn(shadowJar)

with:

jar {
    enabled = false
    dependsOn(shadowJar { classifier = null })
}

Verify:

$ gradle assemble --console=plain
:compileJava
:processResources NO-SOURCE
:classes
:shadowJar
:jar SKIPPED
:assemble UP-TO-DATE
like image 25
Funk Avatar answered Nov 16 '22 08:11

Funk


Perhaps disabling the jar task in build.gradle will work

apply plugin: 'java'
jar.enabled = false

So you will only have your uber jar.

like image 5
Eugene S Avatar answered Nov 16 '22 09:11

Eugene S