【发布时间】:2021-10-14 00:46:08
【问题描述】:
我正在使用带有 Gradle 插件的 Eclipse 4.20.0。 (Gradle 版本 6.6) 我创建了一个罐子。 我创建了另一个引用这个 jar 的项目。 我想调试最后一个项目,但是当调用jar中的一个类时,Eclipse显示扩展名为“.class”的文件,但找不到扩展名为“.java”的源文件并显示“找不到源”“的此类文件的 JAR 属于容器“项目和外部依赖项”,该容器不允许修改其条目上的源附件”
创建 jar 的项目的 build.gradle 文件是:
plugins {
id 'java-library'
}
repositories {
jcenter()
mavenCentral()
}
java {
withSourcesJar() //For including the sources??
}
// My customization
project.jar.destinationDirectory = file("$rootDir/../mytargets") //Save jars in the same folder
project.archivesBaseName = 'a-annotations' //Set the name of the jar file
project.version = '1.0'
dependencies {
testImplementation 'junit:junit:4.13'
}
使用这个jar的项目的build.gradle是
plugins {
id 'java-library'
id 'java-library-distribution'
}
repositories {
jcenter()
mavenCentral()
}
java {
withSourcesJar() //For including the sources??
}
// My customization
project.jar.destinationDirectory = file("$rootDir/../mytargets") //Save jars in the same folder
project.archivesBaseName = 'p-if07-run'
project.version = '1.0'
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
api files('../mytargets/a-annotations-1.0.jar') // The jar !!!!
}
// Collect all the dependencies into the folder "lib"
jar {
manifest {
attributes(
'Main-Class': 'Execute',
'Class-Path': configurations.runtimeClasspath.files.collect { 'lib/'+it.getName() }.join(' ')
)
}
}
【问题讨论】: