Gradle eclipse plugin unable to attach source code

摘要: The source code is attached to the JAR, but Eclipse is keep showing “Source not found” while I jumped to the source via “F3 – Open Declaration”.

The source code is attached to the JAR, but Eclipse is keep showing “Source not found” while I jumped to the source via “F3 – Open Declaration”.

Tools tested :

  1. Gradle 2.4
  2. Eclipse 4.4

1. Gradle Eclipse Project

1.1 A web project build with Gradle and development in Eclipse IDE.

build.gradle
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
//...

1.2 Generate the Eclipse project settings.

$ gradle eclipse

2. Problem – Eclipse Classpath

Review the generated Eclipse classpath, Java Build Path. Gradle create another “Web App libraries” and assign the entire dependencies into it, but without the source code.

And the “Web App Libraries” has the top priority to load.

This is the reason that caused the “Source not found” error message.

2. Solution

To fix it, put the “Web App” libraries to the bottom of the build path.

This Gradle script will always reorder the “Web App libraries” to bottom each time you generate the Eclipse classpath file via Gradle

build.gradle
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
eclipse.classpath.file {
    withXml { xml ->
        def node = xml.asNode()
        node.remove( node.find { it.@path == 'org.eclipse.jst.j2ee.internal.web.container' } )
        node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])

Credit to Andreas Kuhrwahl, see this thread.

Note
I wish that Gradle team would fix this issue soon, a bit funny to put a hack in build.gradle to just attach the source code.

References

  1. WAR + EclipseWtpPlugin Shadows Source Attachments with Web App Libraries Container
  2. Why is Eclipse not attaching 3rd party libs source?

上一篇: Spring MVC + Logback SLF4j example
下一篇: Spring MVC + Mustache JS template example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号