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

Manually remove from pom.xml the dependencies that have been inlined by the shadow plugin #87

Merged
merged 2 commits into from
Sep 23, 2021

Conversation

cyrille-leclerc
Copy link
Member

Description:

Manually remove from pom.xml the dependencies that have been inlined by the shadow plugin as they should no be listed in pom.xml as RUNTIME dependencies

Existing Issue(s):

Testing:

  • Invoke ./gradlew :maven-extension:publishToMavenLocal
  • Verify in ~/.m2/repository/io/opentelemetry/contrib/opentelemetry-maven-extension/1.7.0-alpha-SNAPSHOT/opentelemetry-maven-extension-1.7.0-alpha-SNAPSHOT.pom that the pom doesn't contain any dependency.

Documentation:

N/A

Outstanding items:

@cyrille-leclerc cyrille-leclerc requested a review from a team September 22, 2021 22:49
@cyrille-leclerc
Copy link
Member Author

Hello @anuraaga , I'm sorry to bother you with this.
I saw that you are the author of otel.publish-conventions.gradle.kts so you may know how to configure the MavenPublication to overwrite the dependencies of the generated pom.xml and remove them.

The bug is that the dependencies inlined by the Gradle Shadow plugin are unexpectedly listed in the generated pom.xml as RUNTIME dependencies when it is expected that they are not listed in the pom.xml at all.

The proposed fix seems to do the job but I'm not a Gradle person so I would like to get a review on this.

@anuraaga
Copy link
Contributor

Sure @cyrille-leclerc let me take a look at this tomorrow

@trask
Copy link
Member

trask commented Sep 23, 2021

@cyrille-leclerc welcome to the club of people who ask @anuraaga for shadowJar help 😂

try this:

configure<PublishingExtension> {
  (components["java"] as AdhocComponentWithVariants).run {
    withVariantsFromConfiguration(configurations["runtimeElements"]) {
      skip()
    }
  }
}

@cyrille-leclerc
Copy link
Member Author

Thanks @trask, so we have 2 solutions, yours is way shorter. I have no clue on what's the the most maintainable solution. Maybe @anuraaga can help decide. @trask's solution sounds appealing as it's compact.

configure<PublishingExtension> {
  (components["java"] as AdhocComponentWithVariants).run {
    withVariantsFromConfiguration(configurations["runtimeElements"]) {
      skip()
    }
  }
}

or

publishing {
    (publications) {
      "maven"(MavenPublication::class) {
            pom {
              withXml {
                val pomNode = asNode()
                val dependenciesNode = (pomNode.get("dependencies") as NodeList)[0] as Node
                val dependencyNodes = dependenciesNode.children() as NodeList
                // the jar dependencies bundled in the uber-jar by the shadow plugin are wrongly added as
                // 'runtime' dependencies in the generated pom.xml instead of being absent this pom.xml.
                // Remove those runtime dependencies from the pom.xml:
                dependencyNodes.removeIf {
                  val dependencyNode = it as Node
                  val scope: String = ((dependencyNode.get("scope") as NodeList)[0] as Node).text()
                  val removeDependency = (scope == "runtime" || scope == "compile")
                  logger.debug("pom.xml remove: $removeDependency dependency $dependencyNode")
                  removeDependency
                }
              }
            }
        }
    }
  }

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants