Skip to content

Instantly share code, notes, and snippets.

@oesolutions
Last active June 13, 2016 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oesolutions/e970f32a7aef0873fe914490689a7c15 to your computer and use it in GitHub Desktop.
Save oesolutions/e970f32a7aef0873fe914490689a7c15 to your computer and use it in GitHub Desktop.
Sample for Gradle forum question on binary task dependencies.
@Managed
interface MyCmp extends VariantComponentSpec {
String getSomething()
void setSomething( String something )
}
@Managed
interface MyCmpBinOne extends BinarySpec {
File getFile()
void setFile( File file )
String getContent()
void setContent( String content )
}
@Managed
interface MyCmpBinTwo extends BinarySpec {
File getFile()
void setFile( File file )
String getContent()
void setContent( String content )
}
class MyRuleSource extends RuleSource {
@ComponentType
void registerMyCmp( TypeBuilder<MyCmp> builder ) {}
@ComponentType
void registerBinOne( TypeBuilder<MyCmpBinOne> builder ) {}
@ComponentType
void registerBinTwo( TypeBuilder<MyCmpBinTwo> builder ) {}
@ComponentBinaries
void createBinOneForCmp( ModelMap<MyCmpBinOne> binaries, MyCmp cmp, @Path("buildDir") buildDir ) {
binaries.create( 'binaryOne' ) {
file = new File( buildDir, "${cmp.name}.bin1" )
content = cmp.something
}
}
@ComponentBinaries
void createBinTwoForCmp( ModelMap<MyCmpBinTwo> binaries, MyCmp cmp, @Path("buildDir") buildDir ) {
binaries.create( 'binaryTwo' ) {
file = new File( buildDir, "${cmp.name}.bin2" )
content = cmp.something
}
}
@BinaryTasks
void createBinOneTasks( ModelMap<Task> tasks, MyCmpBinOne binOne ) {
tasks.create( binOne.tasks.taskName( 'generate' ) ) {
outputs.file binOne.file
doLast {
logger.lifecycle( "Building ${binOne.file}." )
binOne.file.parentFile.mkdirs()
binOne.file.text = binOne.content
}
}
}
@BinaryTasks
void createBinTwoTasks( ModelMap<Task> tasks, MyCmpBinTwo binTwo ) {
tasks.create( binTwo.tasks.taskName( 'generate' ) ) {
outputs.file binTwo.file
doLast {
logger.lifecycle( "Building ${binTwo.file}." )
binTwo.file.parentFile.mkdirs()
binTwo.file.text = binTwo.content
}
}
}
}
apply plugin: MyRuleSource
model {
components {
cmpOne( MyCmp )
cmpTwo( MyCmp )
withType( MyCmp ) {
something 'Hello World!'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment