Skip to content

Instantly share code, notes, and snippets.

@Unh0lyTigg
Last active August 29, 2015 14:07
Show Gist options
  • Save Unh0lyTigg/45532631ea4adea35a24 to your computer and use it in GitHub Desktop.
Save Unh0lyTigg/45532631ea4adea35a24 to your computer and use it in GitHub Desktop.
configurations {
attachSource
}
def loadSourcePaths() {
def result = new HashMap<String, String>()
configurations.attachSource.each {
def depFile = file(it)
def filename = depFile.getName()
def depname = filename.substring(0, filename.indexOf('-'))
result.put(depname, it) // maps based on artifact id
}
result
}
eclipse.classpath.file {
withXml {
def sourcePaths = loadSourcePaths()
def root = it.asNode()
root.children().each { child ->
def attr = child.attributes()
if ('lib'.equals(attr.get('kind'))) { // only attach to libraries
def path = attr.get('path')
def pathfile = file(path)
def filename = pathfile.getName()
def dep = filename.substring(0, filename.contains('-') ? filename.indexOf('-') : filename.length() - 1) // should match the artifactId from the gradle configuration
if (sourcePaths.containsKey(dep)) { // ignore if we don't need to attach a custom source to this library
def srcpath = sourcePaths.get(dep)
attr.put('sourcepath', srcpath)
}
}
}
}
}
// This is all that's needed for the example
// with forgegradle, place this line just after any of the "apply plugin: '...'" lines
apply from: '../attach.gradle' // might want to remove the "../" if you place attach.gradle in the same folder as build.gradle
// place the rest of this at the end of the file (or merge with the repositories & dependencies blocks you already have) (these repos and dependencies are provided as an example of the attach.gradle system)
repositories {
maven {
name "CB Repo"
url "http://chickenbones.net/maven"
}
maven {
name "Forge Repo"
url "http://files.minecraftforge.net/maven"
}
}
dependencies {
compile 'codechicken:CodeChickenCore:1.7.10-1.0.4.29:dev'
compile 'codechicken:CodeChickenLib:1.7.10-1.1.1.105:dev'
compile 'codechicken:ForgeMultipart:1.7.10-1.1.0.311:dev'
compile 'codechicken:NotEnoughItems:1.7.10-1.0.3.62:dev'
attachSource 'codechicken:CodeChickenCore:1.7.10-1.0.4.29:src'
attachSource 'codechicken:CodeChickenLib:1.7.10-1.1.1.105:src'
attachSource 'codechicken:ForgeMultipart:1.7.10-1.1.0.311:src'
attachSource 'codechicken:NotEnoughItems:1.7.10-1.0.3.62:src'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment