use*_*mda 6 java dependency-management gradle multi-module
I have a multi-module project in Gradle.
I refactored the common functionality into a module named common.
I have tests in a different module (lets say module A) of the multi-module project that consume the classes under src/main/java of the common module.
I am able to import these classes from common module in test classes of module A, but when I run the tests, I get the following error:
error: package 'common.bla...' does not exist.
This is the build.gradle file for module A that depends on common module for its tests (I have tried all these options):
dependencies {
compile project(':common')
testCompile project(':common')
testRuntime project(':common')
runtime project(':common')
implementation project(":common")
testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'
implementation 'junit:junit:4.12'
testCompileOnly project(':common')
testRuntimeOnly project(':common')
testImplementation project(':common')
runtimeOnly project(':common')
testCompile project(":common").sourceSets.test.output
compile project(":common").sourceSets.test.output
testRuntime fileTree(dir: 'libs', include: ['*.jar'])
}
Run Code Online (Sandbox Code Playgroud)
I have also verified that a jar is created in common/build/libs.
What else can I try?
现在的依赖关系很复杂。两者兼而有之compile,testCompile即使testCompileOnly不是完全错误,也是令人困惑的。testCompileOnly可能是它\xe2\x80\x99s 在运行时不工作的原因。
拥有compile也意味着运行时和测试编译。您可以使用 来检查gradlew common:dependencies。
我认为清理依赖关系会有所帮助。如果没有,请检查 jar 的内容以包含预期的类。
\n| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |