How to include Zip file inside ShadowJar during Gradle build

I provide below what I have at the moment.

In the example below, the Jar task creates a Jar with a Zip file inside it (an artifact from another project).

But, My ultimate goal is to create an uber jar that will contain its own dependencies. I came with the Shadow plugin and it seems like a clean solution.

I tried to tell my ShadowJar task to include the Zip file, but it doesn't work. See the comment in the ShadowJar section.

So now I have to create a shadow jar, but then create another jar that includes the contents of the shadow jar and a zip. I see this path is full of gotchas (I had to execute the manifest again) ....

Ideally, I would think there is a way to include an artifact from a different configuration in the Shadow Jar, and this is my limitation of Gradle knowledge that doesn't work here.

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

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

    project.version = rootProject.ext.deployerVersion


    // In this section you declare where to find the dependencies of your project
    repositories {
        // Use 'maven central' for resolving your dependencies.
        // You can declare any Maven / Ivy / file repository here.
        mavenCentral ()
    }

    configurations {
         pkg
    }

    // In this section you declare the dependencies for your production and test code
    dependencies {
        compile project (': Concenter.Foundation') 
        pkg project (path: ': Concenter.Platform', configuration: 'pkg')

        // Declare the dependency for your favorite test framework you want to use in your tests.
        // TestNG is also supported by the Gradle Test task. Just change the
        // testCompile dependency to testCompile 'org.testng: testng: 6.8.1' and add
        // 'test.useTestNG ()' to your build script.
        testCompile 'junit: junit: 4.11'
    }

    jar {
        dependsOn ': Concenter.Platform: distZip'
        manifest {
             attributes (
                'Main-Class': 'aqilco.concenter.deployer.Deployer',
             )
        }
        from configurations.pkg
    }

    / *
    shadowJar {
        dependsOn ': Concenter.Platform: distZip'
        manifest {
             attributes (
                'Main-Class': 'aqilco.concenter.deployer.Deployer',
             )
        }
        from configurations.pkg
    }
    * /

    task pkg (type: Jar) {
        dependsOn ': Concenter.Platform: distZip'
        dependsOn 'shadowJar'
        archiveName = jar.baseName + "-" + jar.version + "-pkg." + jar.extension
        from zipTree (shadowJar.archivePath)
        from configurations.pkg
        manifest {
             attributes (
                'Main-Class': 'aqilco.concenter.deployer.Deployer',
             )
        }
    }

+3


source to share





All Articles