Gradle - 如何为maven依赖指定javadoc位置jar文件?

时间:2013-08-29 18:04:20

标签: java maven eclipselink gradle

我想将本地javadoc jar添加到maven依赖项。可能吗?如果是,我该怎么办?问题是我有maven依赖,其中包含传递jar

dependencies {
    compile 'org.eclipse.persistence:eclipselink:2.5.0'
}

gradle dependencies命令返回了这个:

compile - Compile classpath for source set 'main'.
+--- org.eclipse.persistence:eclipselink:2.5.0
     +--- org.eclipse.persistence:javax.persistence:2.1.0
     \--- org.eclipse.persistence:commonj.sdo:2.1.1

主依赖项eclipselink包含javax.persistence的javadoc,所以我在eclipse编辑器中看不到javadoc提示。我想要做的是将eclipselink javadoc连接到javax.persistence

这就是我的期望:

dependencies {
    compile 'org.eclipse.persistence:javax.persistence:2.1.0' {
        javadoc = <path to javadoc>
    }
}

1 个答案:

答案 0 :(得分:2)

问题解决了。我已经使用gradle .classpath插件编辑了eclipse eclipse文件,它可以做到它应该做的事情。这是代码:

eclipse {
    classpath {
       downloadSources=true
       downloadJavadoc=true
        file {
            withXml {
                def node = it.asNode()
                // find eclipselink javadoc path
                def eclipselinkPath = configurations.compile.find { it.absolutePath.contains('eclipselink') }
                def javaxPersistenceJavadocPath = ""
                node.each {
                    def filePath = it.attribute('path')
                    if (file(filePath) == file(eclipselinkPath)) {
                        javaxPersistenceJavadocPath = it.attributes.attribute.@value[0]
                    }
                }
                // add eclipselink javadoc path as attribute to javax.persistence
                def javaxPersistencePath = configurations.compile.find { it.absolutePath.contains('javax.persistence') }
                node.each {
                    def filePath = it.attribute('path')
                    if (file(filePath) == file(javaxPersistencePath)) {
                        it.appendNode('attributes').appendNode('attribute', [name:'javadoc_location', value:javaxPersistenceJavadocPath])
                    }
                }
            }
        }
    }
}

我知道它看起来很丑,但我没有更多时间来解决这个问题。顺便说一句,这不是我的问题的根源(我有依赖关系或gradle缓存的问题,我还不知道)。