k. I played around with this for an hour and came up with a scripted approach
that's almost working. I'm okay keeping the sources in the gradle cache.
configurations {
sources {
description = "Sources for external jars"
transitive = false
}
}
dependencies {
...
// You can do this here or in the task..you can also add direct
dependencies to sources for special cases
configurations.compile.dependencies.each { d ->
sources "${d.group}:${d.name}:${d.version}:sour...@jar"
...
}
and stuck in the following into a task.
// How to use:
// a) Run gradle eclipsCp to generate the classpath from the dependencies.
// b) Run gradle modifyEclipseClasspath to generate the source entries.
// c) Copy .classpath.new to .classpath
// d) Select the eclipse project (topmost folder). Press F5 or File>Refresh.
//
// Many respositories do not keep sources so it may seem like its not
working
// but its because a source artifact may not have been uploaded. If a
sourcepath
// is already defined, it is NOT overwritten--user defined source paths take
precedence.
// Delete the user defined sourcepath if you want this task to fill it in
from gradle.
task modifyEclipseClasspath {
// Create dependencies so they are downloaded. We could put this in the
dependencies { } builder section.
configurations.compile.copyRecursive{it instanceof
ExternalModuleDependency}.dependencies.each { d ->
dependencies { sources
"${d.group}:${d.name}:${d.version}:sour...@jar" }
}
// For each entry in the eclipse classpath, add the "sourcepath"
attribute
def f = new File(".classpath")
if(f == null) {
logger.error("Eclipse .classpath file is not accessible in the
current
directory")
return
}
def x = new groovy.util.XmlSlurper().parse(f)
x.classpathentry.findAll{ i...@kind == 'lib'}.each {
def path = [email protected]()
// rely on the gradle .cache file structure
def v = path.split('/')
def jar = v[-1]
def group = v[-4]
def name = v[-3]
def version = (jar =~ /-(\d+\.\d+.\d+).*\.jar/)[0][1]
logger.info "Source dependency derived from jar in
classpathentry.path: $group, $name, $version"
def d = configurations.sources.dependencies.find{
(it.group == group) && (it.name == name) && (it.version
=
version)}
logger.info "Sources configuration return the following
dependency:
" + d
if(d != null && i...@sourcepath != null) {
logger.info "Class of d: " + d.getClass()
def ff = configurations.sources.files(d)
logger.info "Class of ff: " + ff.getClass() + ",
value=" + ff
if(ff.size() >= 1) {
i...@sourcepath = ff.toArray()[0].absolutePath
} else
logger.info "Could not attach sourcepath to
classpathentry,
dependency was not resolved to a file"
} else
logger.info "Sources dependency not found for
dependency: " + d
}
def mb = new groovy.xml.StreamingMarkupBuilder().bind{mkp.yield x}
def fnew = new File(".classpath.new")
logger.info "Writing new eclipse classpath to: " + fnew
mb.writeTo(new java.io.PrintWriter(fnew))
}
I have not tested this much yet but it seemed to work for simple cases.
A task which prints the dependencies out:
task testSourceDependencies(dependsOn: modifyEclipseClasspath) {
println "Printing configurations.compile"
configurations.compile.each { println "" + it }
println "Printing configurations for sources"
configurations.sources.each { println "" + it }
}
On 29/12/09 4:25 AM, aappddeevv wrote:
> How can you attach the sources to the compile configuration so that the
> eclipse plugin adds the sources (via the sourcepath attribute) to the
> proper
> jar entry in the .classpath file?
>
>
You can't yet. The JIRA issue for this is:
http://jira.codehaus.org/browse/GRADLE-238
--
View this message in context:
http://old.nabble.com/Downloading-*-sources-tp26529227p26957224.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email