Closed stonier closed 11 years ago
It's possible, but this gets really complicated really quickly. I have a script below which goes most of the way:
dependencies {
compile project(':message_generator')
}
def generatedSourcesDir = "${buildDir}/generated-src"
def List<String> packageList = new ArrayList<String>()
packageList.add("std_msgs")
packageList.add("rosgraph_msgs")
task generateSources(type: JavaExec) {
description "Generate all pkg sources and store in build/generated-src"
outputs.dir file(generatedSourcesDir)
args new ArrayList<String>([ generatedSourcesDir ] + packageList)
classpath = configurations.runtime
main = 'org.ros.internal.message.GenerateInterfaces'
}
configurations {
messageArchives {
description = 'generated message sources for ${packageList}.'
}
}
packageList.each { pkg ->
configurations {
"${pkg}" {
description = 'generated message sources for ${pkg}'
}
}
/* Once sourceSets are defined, java will add compileXYZJava, XYZClasses tasks */
sourceSets {
"${pkg}" {
java {
srcDir generatedSourcesDir + "/${pkg}"
}
if ( pkg == 'rosgraph_msgs' ) {
compileClasspath += std_msgs.output
}
}
}
def funnyPkgName=pkg.capitalize()
tasks["compile${funnyPkgName}Java"].dependsOn generateSources
if ( pkg == 'rosgraph_msgs' ) {
tasks["compile${funnyPkgName}Java"].dependsOn compileStd_msgsJava
}
dependencies {
"${pkg}Compile" project(':message_generator')
"${pkg}Runtime" project(':message_generator')
if ( pkg == 'rosgraph_msgs' ) {
"${pkg}Compile" project(':message_generator')
}
}
task "${pkg}Jar"(type: Jar) {
baseName "${pkg}"
from sourceSets["${pkg}"].output
}
artifacts {
messageArchives tasks["${pkg}Jar"]
}
}
uploadMessageArchives {
repositories {
mavenDeployer {
repository(url: 'file:///home/snorri/tmp/maven')
packageList.each { pkg ->
addFilter("${pkg}") { artifact, file ->
artifact.name == "${pkg}"
}
}
}
}
}
task dude {
configurations.each { c ->
println c
}
configurations.findAll().each { config ->
println "${config}:"
config.allArtifacts.getFiles().each { file -> println " Artifact: " + file}
config.allDependencies.each { dep -> println " Dependency: " + dep}
println ' '
}
}
eclipse.classpath.file {
withXml {
// TODO(damonkohler): Avoid repetition of build directory. This is
// necessary because Eclipse wants a project relative path.
it.asNode().appendNode('classpathentry', [kind: 'src', path: 'build/generated-src'])
}
}
It's starting to define alot of custom tasks though. And a bigger showstopper is getting the dependencies right (e.g. rosgraph_msgs needs std_msgs). I haven't got that last part in the above script working and making its way into the pom which gets published yet. It needs a line like:
"${pkg}Compile" configuration: 'messageArchives', group: 'org.ros.rosjava_messages', name: 'std_msgs', version: '0.1.0'
in the dependencies, but I've not really any idea what values makes it work.
Probably easier having a script which can spawn subprojects.
Ach, this is old. Eventually done through groovy logic in the build.gradle scripts and a jenkins scraper job which updated package dependency lists in the hydro branch.
Instead of having multiple msg packages bundled in rosjava_messages' artifact, break them out using some gradle glue with multiple artifact generation. Some notes on handling the dependencies also here.