Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial ConfigureShadowRelocation task #330

Open
maniax89 opened this issue Oct 5, 2017 · 2 comments
Open

Partial ConfigureShadowRelocation task #330

maniax89 opened this issue Oct 5, 2017 · 2 comments

Comments

@maniax89
Copy link

maniax89 commented Oct 5, 2017

Basically, I have been trying to figure out a way to create an partial "uber" jar. The documentation clearly states that by default it will create an "uber" jar from the shadowJar task, but I was interested in the proper way to only include one of the dependencies, say dependency A (as well as A's dependencies) AND relocate all the packages of dependency A as well. I believe that http://imperceptiblethoughts.com/shadow/#using_shadow_to_package_gradle_plugins adds in the ConfigureShadowRelocation task which achieves my goal, but it seems to do it for ALL dependencies (not sure how to just pick one dependency, dependency A).

Configuring the relocation has always been possible, but the build author is required to know all the package names before hand. Shadow v2.0 corrects this by introducing a new task type ConfigureShadowRelocation. Tasks of this type are configured to target a an instance of a ShadowJar task and run immediately before it.

See below for my configuration

Shadow Version

2.0.1

Gradle Version

Gradle 4.1

Gradle Build Script(s)

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

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

dependencies {
  compile "A"
  compile "B"
  compile "C"
}

shadowJar {
  //what do i put here to just do relocation for "A"
}
@maniax89
Copy link
Author

maniax89 commented Oct 5, 2017

So here's my new configuration:

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

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

configurations {
    shadowAndCompile
    compile.extendsFrom(shadowAndCompile)
}

dependencies {
    shadowAndCompile 'A'
    compile 'B'
    compile 'C'
}

configureRelocationShadowJar {
    prefix = "somecustomprefix"
}

shadowJar {
    configurations = [project.configurations.shadowAndCompile]
}

artifacts {
    archives shadowJar
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: mavenLocal().url)
            pom.whenConfigured {
                p -> p.dependencies = p.dependencies.findAll {
                    dep -> dep.groupId != "A"
                }
            }
            pom.groupId = "my.group"
            pom.artifactId = "my-artifact"
            pom.version = "1.0.0"
        }
    }
}

Does this look like the right way to go about this?

I wasn't sure how to make the uploadShadow task to only remove the shadowed dependencies from the POM (and leave the rest of the compile dependencies)

@johnrengelman
Copy link
Collaborator

Your solution looks good for the compilation part.
You might not need the pom configuration if you change compile.extendsFrom(shadowCompile) to compileClasspath.extendsFrom(shadowCompile)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants