How to attach the source to the jar in the Gradle (Gradle 6.3.) build that can be used in eclipse External Dependencies

huangapple go评论49阅读模式
英文:

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依赖项。当我尝试浏览方法调用层次结构时,它不显示实际的代码,而是显示像下面图片中显示的内容。

How to attach the source to the jar in the Gradle (Gradle 6.3.) build that can be used in eclipse External Dependencies

我想要为外部依赖项附加源代码,我尝试通过选择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
How to attach the source to the jar in the Gradle (Gradle 6.3.) build that can be used in eclipse External Dependencies

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: &#39;org.springframework.boot&#39;, name: &#39;spring-boot-gradle-plugin&#39;, version: &#39;2.1.3.RELEASE&#39;)
}
}
apply plugin: &#39;maven-publish&#39;
apply plugin:&#39;java&#39;
apply plugin: &#39;eclipse&#39;
apply plugin: &#39;org.springframework.boot&#39;
apply plugin: &#39;io.spring.dependency-management&#39;
configurations.all {
exclude group: &quot;commons-logging&quot;, module: &quot;commons-logging&quot;
exclude group: &quot;org.springframework.boot&quot;, module: &quot;spring-boot-starter-tomcat&quot;
}
configurations {
javadocJar
}
dependencies {
implementation(group: &#39;javax.servlet&#39;, name: &#39;javax.servlet-api&#39;, version: &#39;3.1.0&#39;)
implementation (group: &#39;org.springframework.retry&#39;, name: &#39;spring-retry&#39;)
implementation(group: &#39;com.google.guava&#39;, name: &#39;guava&#39;, version: &#39;27.0.1-jre&#39;)
implementation(group: &#39;org.springframework.boot&#39;, name: &#39;spring-boot-starter-web&#39;)
implementation(group: &#39;org.springframework.boot&#39;, name: &#39;spring-boot-starter-actuator&#39;)
implementation group: &#39;commons-io&#39;, name: &#39;commons-io&#39;, version: &#39;2.5&#39;
implementation group: &#39;commons-httpclient&#39;, name: &#39;commons-httpclient&#39;, version: &#39;3.1&#39;
implementation group: &#39;org.apache.httpcomponents&#39;, name: &#39;httpmime&#39;, version: &#39;4.1&#39;
implementation group: &#39;commons-codec&#39;, name: &#39;commons-codec&#39;, version: &#39;1.2&#39;
implementation group: &#39;org.apache.httpcomponents&#39;, name: &#39;httpclient&#39;, version: &#39;4.5&#39;
implementation group: &#39;org.apache.httpcomponents&#39;, name: &#39;httpcore&#39;, version: &#39;4.4.1&#39;
.
. &lt;Some more dependencies&gt;
.
testImplementation(group: &#39;org.powermock&#39;, name: &#39;powermock-api-mockito2&#39;, version: &#39;2.0.0-beta.5&#39;)
testImplementation(group: &#39;org.mockito&#39;, name: &#39;mockito-core&#39;, version: &#39;2.19.0&#39;)
testImplementation(group: &#39;org.powermock&#39;, name: &#39;powermock-module-junit4&#39;, version: &#39;2.0.0-beta.5&#39;)
}
javadoc {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
destinationDir = file(&quot;${buildDir}/docs/javadoc&quot;)
failOnError = true
}
task javadocJar (type: Jar, dependsOn: javadoc){
from javadoc.destinationDir
archiveFileName = &quot;myapps-pco-demo-doc-${version}.jar&quot;
}
jar {
bootJar.enabled = false
jar.enabled = true
dependsOn &#39;javadocJar&#39;
archiveFileName = provider {
&#39;pocdemo.jar&#39;
}
enabled = true
manifest{
attributes(&#39;Sealed&#39;: &#39;true&#39;)
}
}
/* 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.

huangapple
  • 本文由 发表于 2020年7月31日 15:16:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63187382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定