Last active
June 13, 2016 22:32
-
-
Save oesolutions/e970f32a7aef0873fe914490689a7c15 to your computer and use it in GitHub Desktop.
Sample for Gradle forum question on binary task dependencies.
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
@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