athom
athom

Reputation: 1598

Gradle java-library dependency issues

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?

Upvotes: 2

Views: 848

Answers (1)

athom
athom

Reputation: 1598

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 }
}

Upvotes: 2

Related Questions