Created
April 16, 2013 08:43
-
-
Save ritalin/5394398 to your computer and use it in GitHub Desktop.
Gradleのスクリプトから、Eclipse Maven Project吐くためのタスクとか .classpathのカスタマイズは、http://d.hatena.ne.jp/int128/20121010/1349884711 に助けられました。
This file contains hidden or 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
eclipse { | |
project { | |
natures = [ | |
'org.eclipse.jdt.core.javanature', | |
'org.eclipse.m2e.core.maven2Nature' | |
] | |
buildCommand 'org.eclipse.m2e.core.maven2Builder' | |
} | |
classpath { | |
containers = [ | |
'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7', | |
'org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER' | |
] | |
file { | |
whenMerged { classpath -> | |
classpath.configure classpath.entries.grep { entry -> | |
!(entry instanceof org.gradle.plugins.ide.eclipse.model.Library) | |
} | |
} | |
} | |
} | |
} | |
task pom (dependsOn: 'eclipse') << { | |
def dir = "${projectDir.absolutePath}".replaceAll('[\\\\]', '/') | |
def parser = new XmlSlurper(false, false) | |
def doc = parser.parse(new File("${dir}/pom.xml.default")) | |
def repos = doc.repositories.repository | |
.collect { repo -> | |
repo.url.toString() | |
} | |
.toSet() | |
def celtralRepo = repositories.mavenCentral().getUrl().toString() | |
def reposDiff = repositories.grep { | |
def url = it.getUrl().toString() | |
(url != celtralRepo) && (! repos.contains(url)) | |
} | |
reposDiff.each { r -> | |
def repoUrl = r.getUrl().toString() | |
def repoId = r.getUrl().getHost() | |
doc.repositories.appendNode { | |
repository { | |
'id' repoId | |
'name ' repoId | |
'url' repoUrl | |
} | |
} | |
} | |
def deps = doc.dependencies.dependency | |
.collect { | |
new Tuple(it.groupId.toString(), it.artifactId.toString(), it.version.toString()) | |
} | |
.toSet() | |
def depsDiff = configurations.compile.dependencies | |
.grep { | |
! deps.contains(new Tuple(it.getGroup(), it.getName(), it.getVersion())) | |
} | |
depsDiff.each { d -> | |
doc.dependencies.appendNode { | |
dependency { | |
'groupId' d.getGroup() | |
'artifactId' d.getName() | |
'version ' d.getVersion() | |
} | |
} | |
} | |
def output = new File("${dir}/pom.xml"); | |
def xml = groovy.xml.XmlUtil.serialize(new groovy.xml.StreamingMarkupBuilder().bind { | |
mkp.yield doc | |
}) | |
output.write(xml) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment