[英]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'
.
. <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
}
}
我在使用 Spring Tool Suite 時也遇到了同樣的問題,我花了很多時間調查但找不到任何解決方案。 但是當我使用 Intellij 時,它工作正常,我可以將 go 放入 class 文件並進行調試。 所以請嘗試使用 Intellij。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.