【问题标题】:Eclipse & Grade how to generate jar so that debugger can access the source code?Eclipse & Grade 如何生成 jar 以便调试器可以访问源代码?
【发布时间】: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(' ')
    ) 
  }
}

【问题讨论】:

    标签: eclipse debugging gradle


    【解决方案1】:

    最后,用这个替换build.gradle文件的jar部分,解决了我的问题

    jar {   
        from sourceSets.main.allSource  //Include java sources
    }
    

    【讨论】:

      猜你喜欢
      • 2019-09-08
      • 1970-01-01
      • 2014-12-02
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      • 2019-11-10
      • 2021-02-27
      相关资源
      最近更新 更多