Skip to content

Instantly share code, notes, and snippets.

@Ithildir
Last active October 30, 2015 23:55
Show Gist options
  • Save Ithildir/65ec9d6aaf34cea68849 to your computer and use it in GitHub Desktop.
Save Ithildir/65ec9d6aaf34cea68849 to your computer and use it in GitHub Desktop.
Shareable Eclipse project files in Gradle
import groovy.xml.*
apply plugin: "eclipse"
apply plugin: "java"
task copyLibs(type: Copy)
configurations {
libs
}
copyLibs {
from configurations.runtime
into "lib"
}
dependencies {
compile "commons-io:commons-io:2.4"
compile "org.apache.commons:commons-lang3:3.4"
libs fileTree(copyLibs.destinationDir, include: "*.jar")
}
eclipse {
classpath {
downloadJavadoc = false
downloadSources = false
file {
withXml {
xmlProvider ->
def classpathNode = xmlProvider.asNode()
def classpathentryNodes = classpathNode.children()
def libNodes = classpathentryNodes.findAll {
it.@kind == "lib"
}
libNodes.each {
def path = relativePath(it.@path)
it.@path = path.replace('\\' as char, '/' as char)
}
classpathentryNodes.sort(true) {
it.@kind + it.@path
}
}
}
minusConfigurations += [configurations.runtime]
plusConfigurations += [configurations.libs]
}
}
eclipseClasspath {
dependsOn copyLibs
doLast {
def classpathFile = file(".classpath")
def classpathFileContent = classpathFile.text
classpathFile.withWriter {
XmlUtil.serialize(classpathFileContent, it)
}
println classpathFile.text
}
}
tasks.eclipse {
dependsOn cleanEclipse
}
repositories {
mavenLocal()
mavenCentral()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment