Assistance converting ant build to gradle


(Gary Jones) #1

I’m attempting to convert a multi-project ant build into gradle. Due to workload constraints, we need to convert to gradle and then begin re-arranging the code to match conventions as workloads permit.

The ant build builds both a war file and jar files from the same source. I’m trying to set up the build to allow it to be ran as gradle build buildBatch so that I can generate both sets of artifacts in one step. I’m having difficulties getting the dependencies from the child project (not the classes, that part works) to flow to the parent. See build scripts below - the java plugin is applied from the parent script. The final goad is to have the batch build generate the jar files and gather the dependencies into a lib directory for distribution. Is this the correct approach? If not, what is the best way to proceed knowing that I cannot reorganize the source at this point?

  • Parent -
configurations {
	batch
}

sourceSets {
	batch {
		java {
			srcDir 'src/main/java'
		}
	}
}
dependencies {
	compile project (':shared')
	compileOnly "org.jboss.spec:jboss-javaee-7.0:${jeeVersion}"

	batchCompile project(path: ':AlchemyShared', configuration: 'batch')
}
task batchJar(type: Jar) {
	baseName = 'alchemy-shared-batch'
	dependsOn classes
	from sourceSets.batch.output
}

artifacts {
	batch batchJar
}
  • Child -
configurations {
	batch
	batchCompile.extendsFrom(compile)
}

sourceSets {
	batch {
		java {
			srcDir 'src/main/java'
		}
	}
}
dependencies {
	compileOnly "org.jboss.spec:jboss-javaee-7.0:${jeeVersion}"
	compile 'org.apache.commons:commons-lang3:3.4'

	batchCompile 'org.jboss.logging:jboss-logging:3.3.0.Final'
	batchCompile('org.postgresql:postgresql:9.3-1102-jdbc4') {
		exclude group: 'org.slf4j', module: 'slf4j-simple'
	}
	batchCompile 'org.apache.commons:commons-lang3:3.4'
}

task batchJar(type: Jar) {
	baseName = 'alchemy-shared-batch'
	dependsOn classes
	from sourceSets.batch.output
}

artifacts {
	batch batchJar
}