Transient library compileClasspath

Hi,

This is my first post.

I looked for several posts that could help me, but I confess that I’m a little confused.

I’m migrating my project from gradle 3.2.1 to 7.4.2.

But I came across the following problem:

In my project we use a dependency (library) developed by a company and it is published in an internal repository (I am not authorized to change and/or modify it)

--- Project SystemRoot
|---------Project Core (Library)
|---------Project Module A (War)
|---------Project Module B (War)

Project Core (Library) - gradle.build:

dependencies {
    testImplementation(libs.junit)
    implementation(libs.logback)
    implementation (libs.framework.core)
    implementation (libs.framework.opc)
    implementation(libs.framework.logger)
    implementation(libs.javaee.api)
    annotationProcessor(libs.jpa.modelgen)
    implementation(libs.jwt)
    implementation(libs.commons.collections4)
    implementation(libs.zxing.core)
    implementation(libs.zxing.javase)
}

compileClasspath:

------------------------------------------------------------
compileClasspath - Compile classpath for source set 'main'.
+--- com.xxxxxxxx.frameworkee:FrameworkCore:3.0.1
+--- com.xxxxxxxx.frameworkee:FrameworkOpc:3.0.1
+--- com.xxxxxxxx.frameworkee:FrameworkLogger:3.0.1
+--- ch.qos.logback:logback-classic:1.2.3
|    +--- ch.qos.logback:logback-core:1.2.3
|    \--- org.slf4j:slf4j-api:1.7.25
+--- javax:javaee-api:7.0
|    \--- com.sun.mail:javax.mail:1.5.0
|         \--- javax.activation:activation:1.1
+--- org.eclipse.persistence:org.eclipse.persistence.oracle:2.6.4
|    \--- org.eclipse.persistence:javax.persistence:2.1.1
+--- com.auth0:java-jwt:3.10.0
+--- org.apache.commons:commons-collections4:4.4
+--- com.google.zxing:core:3.4.0
\--- com.google.zxing:javase:3.4.0
     +--- com.google.zxing:core:3.4.0
     \--- com.beust:jcommander:1.72

(*) - dependencies omitted (listed previously)

runtimeClasspath :

runtimeClasspath - Runtime classpath of source set 'main'.
+--- ch.qos.logback:logback-classic:1.2.3
|    +--- ch.qos.logback:logback-core:1.2.3
|    \--- org.slf4j:slf4j-api:1.7.25
+--- com.xxxxxxxx.Framework:FrameworkCore:3.0.1
|    +--- javax:javaee-api:7.0
|    |    \--- com.sun.mail:javax.mail:1.5.0
|    |         \--- javax.activation:activation:1.1
|    +--- com.xxxxxxxx.Framework:FrameworkUtil:3.0.1
|    |    +--- javax:javaee-api:7.0 (*)
|    |    +--- com.google.guava:guava:24.0-jre
|    |    |    +--- com.google.code.findbugs:jsr305:1.3.9
|    |    |    +--- org.checkerframework:checker-compat-qual:2.0.0
|    |    |    +--- com.google.errorprone:error_prone_annotations:2.1.3
|    |    |    +--- com.google.j2objc:j2objc-annotations:1.1
|    |    |    \--- org.codehaus.mojo:animal-sniffer-annotations:1.14
|    |    +--- ch.qos.logback:logback-classic:1.2.3 (*)
|    |    \--- org.apache.httpcomponents:httpclient:4.5.7
|    |         +--- org.apache.httpcomponents:httpcore:4.4.11
|    |         +--- commons-logging:commons-logging:1.2
|    |         \--- commons-codec:commons-codec:1.11 -> 1.12
|    +--- com.xxxxxxxx.Framework:FrameworkTerminaisOperacaoFacade:3.0.1
|    |    +--- javax:javaee-api:7.0 (*)
|    |    +--- com.xxxxxxxx.Framework:FrameworkUtil:3.0.1 (*)
|    |    +--- com.fasterxml.jackson.core:jackson-core:2.9.0.pr3 -> 2.10.0.pr3
|    |    +--- com.fasterxml.jackson.core:jackson-databind:2.9.0.pr3 -> 2.10.0.pr3
|    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.0.pr3
|    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.10.0.pr3
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0.pr3 -> 2.10.0.pr3
|    |    \--- ch.qos.logback:logback-classic:1.2.3 (*)
|    +--- ch.qos.logback:logback-classic:1.2.3 (*)
|    \--- org.hibernate:hibernate-jpamodelgen:5.4.2.Final
|         +--- org.jboss.logging:jboss-logging:3.3.2.Final
|         +--- javax.xml.bind:jaxb-api:2.3.1
|         |    \--- javax.activation:javax.activation-api:1.2.0
|         \--- org.glassfish.jaxb:jaxb-runtime:2.3.1
|              +--- javax.xml.bind:jaxb-api:2.3.1 (*)
|              +--- org.glassfish.jaxb:txw2:2.3.1
|              +--- com.sun.istack:istack-commons-runtime:3.0.7
|              +--- org.jvnet.staxex:stax-ex:1.8
|              +--- com.sun.xml.fastinfoset:FastInfoset:1.2.15
|              \--- javax.activation:javax.activation-api:1.2.0
+--- com.xxxxxxxx.Framework:FrameworkOpc:3.0.1
|    +--- javax:javaee-api:7.0 (*)
|    +--- com.xxxxxxxx.Framework:FrameworkCore:3.0.1 (*)
|    +--- com.xxxxxxxx.Framework:FrameworkAPICore:3.0.1
|    |    +--- javax:javaee-api:7.0 (*)
|    |    \--- com.xxxxxxxx.Framework:FrameworkCore:3.0.1 (*)
|    +--- org.jgroups:jgroups:4.0.8.Final
|    +--- com.prosysopc:Prosys-OPC-UA-Java-SDK-Client-Binary:2.3.2-781
|    +--- com.prosysopc:Opc-Ua-Stack:1.02.337.18
|    \--- org.reflections:reflections:0.9.11
|         +--- com.google.guava:guava:20.0 -> 24.0-jre (*)
|         \--- org.javassist:javassist:3.21.0-GA
+--- com.xxxxxxxx.Framework:FrameworkLogger:3.0.1
|    +--- javax:javaee-api:7.0 (*)
|    +--- com.xxxxxxxx.Framework:FrameworkCore:3.0.1 (*)
|    \--- org.jgroups:jgroups:4.0.8.Final
+--- javax:javaee-api:7.0 (*)
+--- org.eclipse.persistence:org.eclipse.persistence.oracle:2.6.4
|    \--- org.eclipse.persistence:javax.persistence:2.1.1
+--- com.auth0:java-jwt:3.10.0
|    +--- com.fasterxml.jackson.core:jackson-databind:2.10.0.pr3 (*)
|    \--- commons-codec:commons-codec:1.12
+--- org.apache.commons:commons-collections4:4.4
+--- com.google.zxing:core:3.4.0
\--- com.google.zxing:javase:3.4.0
     +--- com.google.zxing:core:3.4.0
     +--- com.beust:jcommander:1.72
     \--- com.github.jai-imageio:jai-imageio-core:1.4.0

runtimeElements - Elements of runtime for main. (n)

But I’m having problems compiling because the transient dependencies of the library (framework) are not being made available in the compileClasspath context.

I searched and verified that the dependencies configured in the framework library POM file are scoped to “runtime”

Example => POM.XML (frameworkCore):

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xxxxxxxxxxx.framework</groupId>
  <artifactId>frameworkCore</artifactId>
  <version>3.0.1</version>
  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.xxxxxxxxxxx.framework</groupId>
      <artifactId>frameworkUtil</artifactId>
      <version>3.0.1</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-jpamodelgen</artifactId>
      <version>5.4.2.Final</version>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>

I have no control over the library. Is there any way to solve this problem?
How to make transient dependencies with scope “runtime” also considered in compileClaspath?

Your problem is, that this is simply an error in that library.
If that cannot be fixed the most proper way to fix it consumer side is a component metadata rule that properly fixes the libraries dependency details as described at Fixing metadata with component metadata rules.

1 Like

Hi, thank you very much for your reply.

I will contact the library development team and request the modification.

I tried to understand the ComponentMetadataRule concept and I confess that I was a little confused. I honestly don’t know how to do it.

Even so, thank you very much

For example in a Kotlin DSL settings script:

dependencyResolutionManagement {
    components {
        withModule("com.xxxxxxxxxxx.framework:frameworkCore") {
            check (id.version == "3.0.1") { "Update work-around for $id" }
            withVariant("compile") {
                withDependencies {
                    add("com.xxxxxxxxxxx.framework:frameworkUtil:3.0.1")
                }
            }
        }
    }
}