0

I have 2 project, the 1st project is depending on javassist and 2nd project is dependint on the 1st and spring-boot-starter-thymeleaf.

The build gradle is like below 1st project

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.javassist:javassist:3.27.0-GA'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

The 2nd project is like below, :bar:hoge is the 1st project.

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation project(':bar:hoge')
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
bootJar {
    mainClassName = 'com.example.koji.Main'
}

If I run the ../gradlew dependencyInsight --dependency javassist --configuration runtimeClasspath, The result is like below.

No dependencies matching given input were found in configuration ':foo:bar:runtimeClasspath'

And gradlew assemble doesn't have javassist.

But If I removed id 'org.springframework.boot' version '2.3.3.RELEASE' from 1st project or implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' from 2nd project, then same command will return like below

org.javassist:javassist:3.27.0-GA
\--- project :bar:hoge
     \--- runtimeClasspath

And gradlew assemble jar has javassist.

Any ideas? Now I need to add javassist dependency at 2nd project explicitly to solve it. Working project https://github.com/kojilin/example-multi

koji lin
  • 667
  • 1
  • 8
  • 12

2 Answers2

1

Maybe the reason comes from here?

https://github.com/gradle/gradle/issues/1473#issuecomment-413333723

so if I applied

dependencyManagement {
    applyMavenExclusions = false
}

It will preserve the library in runtimeClasspath.

koji lin
  • 667
  • 1
  • 8
  • 12
0

If you want to automatically inherit the javassist dependency from :bar:hoge, declare it as api, not implementation.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • My idea is not to expose javassist api. If `foo:bar` is depending on `:bar:hoge` and `:bar:hoge` is depending(eve use implementation) on javassist, should the final jar(runtimeClasspath) should have javassist ? – koji lin Aug 31 '20 at 12:33
  • @kojilin Once you said "_It's weird for me that I need to add javassist dependency at 2nd project._", then you say "_My idea is not to expose javassist api_". Make up your mind. – Abhijit Sarkar Sep 01 '20 at 05:48
  • I don't get it, but thanks for your comment. If I'm adding `implementation 'com.google.guava:guava:29.0-jre'` in 1st project, even I don't add in 2nd project, in 2nd project's runtimeClasspath we still can see guava. – koji lin Sep 01 '20 at 06:17