[英]How to attach the source to the jar in the Gradle (Gradle 6.3.) build that can be used in eclipse External Dependencies
Problem: I have a gradle project in which I am using let's say 'pocdemo.jar' as gradle dependency.问题:我有一个 gradle 项目,我在其中使用“pocdemo.jar”作为 gradle 依赖项。 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.我想为外部依赖附加源,我尝试通过选择 jar -> 属性 -> Java 源附件来做到这一点,但这不允许我添加源的位置。 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.
现在我想知道有没有一种方法可以在 build.gradle 文件中使用,该文件将在 jar 创建过程中包含源代码。 I have the below gradle file for the project that I use as external dependency in my main project.
我在主项目中用作外部依赖项的项目有以下 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'
.
. <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
}
}
I have the same issue too when using Spring Tool Suite, and I spent a lot of time investigating but cannot find any solutions.我在使用 Spring Tool Suite 时也遇到了同样的问题,我花了很多时间调查但找不到任何解决方案。 But when I use Intellij, it works fine, I can go into the class file and debug it.
但是当我使用 Intellij 时,它工作正常,我可以将 go 放入 class 文件并进行调试。 So please try it with Intellij.
所以请尝试使用 Intellij。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.