Last active
October 30, 2015 23:55
-
-
Save Ithildir/65ec9d6aaf34cea68849 to your computer and use it in GitHub Desktop.
Shareable Eclipse project files in Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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