2

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?

1 Answer 1

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 } } 
Sign up to request clarification or add additional context in comments.

2 Comments

hi I am having the same problem as yours, this is my question, stackoverflow.com/questions/73436774/… can you help me on this ?
Hi, you haven't mentioned what was already there in your "publishing" section and how it looks after the fix. If possible , please include that code snippet in your answer or question. thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.