英文:
How to attach the source to the jar in the Gradle (Gradle 6.3.) build that can be used in eclipse External Dependencies
问题
问题:我有一个Gradle项目,其中我使用一个名为'pocdemo.jar'的Gradle依赖项。当我尝试浏览方法调用层次结构时,它不显示实际的代码,而是显示像下面图片中显示的内容。
我想要为外部依赖项附加源代码,我尝试通过选择jar -> 属性 -> Java源代码附件来实现,但是这不允许我添加源代码的位置。现在我想知道是否有一种方式可以在build.gradle文件中使用,使其在jar创建过程中包含源代码。
以下是我在主项目中使用的外部依赖项的Gradle文件。
buildscript {
repositories {
maven {
url = repoUrl
allowInsecureProtocol = true
metadataSources {
mavenPom()
artifact()
}
}
maven {
url = biappsUrl
allowInsecureProtocol = true
metadataSources {
mavenPom()
artifact()
}
}
}
dependencies {
classpath(group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.1.3.RELEASE')
}
}
apply plugin: 'maven-publish'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
}
configurations {
javadocJar
}
dependencies {
implementation(group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0')
implementation (group: 'org.springframework.retry', name: 'spring-retry')
implementation(group: 'com.google.guava', name: 'guava', version: '27.0.1-jre')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-web')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-actuator')
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
implementation group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
implementation group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.1'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.2'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.1'
.
. <一些其他依赖项>
.
testImplementation(group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5')
testImplementation(group: 'org.mockito', name: 'mockito-core', version: '2.19.0')
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5')
}
javadoc {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
destinationDir = file("${buildDir}/docs/javadoc")
failOnError = true
}
task javadocJar (type: Jar, dependsOn: javadoc){
from javadoc.destinationDir
archiveFileName = "myapps-pco-demo-doc-${version}.jar"
}
jar {
bootJar.enabled = false
jar.enabled = true
dependsOn 'javadocJar'
archiveFileName = provider {
'pocdemo.jar'
}
enabled = true
manifest{
attributes('Sealed': 'true')
}
}
/* Eclipse配置 */
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}
注意:代码中的中英文引号可能会在不同的环境下显示不同,但翻译已尽量保留原意。
英文:
Problem: I have a gradle project in which I am using let's say 'pocdemo.jar' as gradle dependency. When I try to navigate through the method call hierarchy, it doesn't show the actual code, instead it shows something like shown in image below
I want to have the source attached for the external dependency, I tried to do that by selecting the jar -> properties -> Java Source Attachment, but that didn't allow me to add the location for the source. Now I want to know is there a way that I can use in build.gradle file that will include the source during the jar creation itself.
I have the below gradle file for the project that I use as external dependency in my main project.
buildscript {
repositories {
maven {
url = repoUrl
allowInsecureProtocol = true
metadataSources {
mavenPom()
artifact()
}
}
maven {
url = biappsUrl
allowInsecureProtocol = true
metadataSources {
mavenPom()
artifact()
}
}
}
dependencies {
classpath(group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.1.3.RELEASE')
}
}
apply plugin: 'maven-publish'
apply plugin:'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
}
configurations {
javadocJar
}
dependencies {
implementation(group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0')
implementation (group: 'org.springframework.retry', name: 'spring-retry')
implementation(group: 'com.google.guava', name: 'guava', version: '27.0.1-jre')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-web')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-actuator')
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
implementation group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
implementation group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.1'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.2'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.1'
.
. <Some more dependencies>
.
testImplementation(group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5')
testImplementation(group: 'org.mockito', name: 'mockito-core', version: '2.19.0')
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5')
}
javadoc {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
destinationDir = file("${buildDir}/docs/javadoc")
failOnError = true
}
task javadocJar (type: Jar, dependsOn: javadoc){
from javadoc.destinationDir
archiveFileName = "myapps-pco-demo-doc-${version}.jar"
}
jar {
bootJar.enabled = false
jar.enabled = true
dependsOn 'javadocJar'
archiveFileName = provider {
'pocdemo.jar'
}
enabled = true
manifest{
attributes('Sealed': 'true')
}
}
/* Eclipse config */
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}
答案1
得分: 1
I have the same issue too when using Spring Tool Suite, and I spent a lot of time investigating but cannot find any solutions.
But when I use Intellij, it works fine, I can go into the class file and debug it. So please try it with Intellij.
英文:
I have the same issue too when using Spring Tool Suite, and I spent a lot of time investigating but cannot find any solutions.
But when I use Intellij, it works fine, I can go into the class file and debug it. So please try it with Intellij.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论