1

I have developed a Java library using the java-library Gradle plugin. This library has e dependency on protobuf-java which I need to expose as a transitive dependency to users of the library.

I have the following snippets in my library's build.gradle

plugins {
    id 'java-library'
    id "maven-publish"
    id "com.google.protobuf" version "0.8.16"
}

...

dependencies {
    api ("com.google.protobuf:protobuf-java:3.17.3")
    testImplementation("com.google.protobuf:protobuf-java-util:3.17.3")
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
    testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.2")
}

Running gradlew dependencies gives me the following as expected

api - API dependencies for source set 'main'. (n)
\--- com.google.protobuf:protobuf-java:3.17.3 (n)

But when I add the library as a dependency to in my main app, I don't get any transitive dependencies. Doing a gradlew dependencies in my main app gives me:

compileClasspath - Compile classpath for source set 'main'.
+--- my-library:my-library:1.0.21
+--- javax.jms:javax.jms-api -> 2.0.1
....

What could be the cause for the dependency not showing up in the main app?

athom
  • 1,428
  • 4
  • 13
  • 26

1 Answers1

2

The problem was with the maven-publish plugin.

I had to add the following to my publishing section to get it to work.

publications {
    mavenJava(MavenPublication) { from project.components.java }
}
athom
  • 1,428
  • 4
  • 13
  • 26
  • hi I am having the same problem as yours, this is my question, https://stackoverflow.com/questions/73436774/extended-class-method-are-not-available-when-exported-as-library can you help me on this ? – Rookie007 Aug 24 '22 at 01:47