See if this helps to some extent. Say you create a custom plugin / class and destroy it with an artifact in Gradle (within the file level GRADLE_HOME / init.d / common.gradle).
The user java / groovy project of the plugin project will look like
// Your custom plugin class file will look like // Your custom plugin source code will reside at: com.mycustom.plugin.gradle under src/main/java folder tree. package com.mycustom.plugin.gradle import org.gradle.api.* import org.gradle.api.file.* import java.io.File; public class myCustomFileUtil { /** * Default constructor */ public myCustomFileUtil() { } /** * Read file returning list of lines. Double slash (//) at start of line * defines a comment. * @param fileName File to read. * @return List of lines. */ public static List readIntoList( String fileName ) { def fname = new File( fileName ) def listFinal = [] def listLines = fname.readLines() listLines.each { it -> def str = it.trim(); if( str.length() > 0 ) { if( ! str.startsWith( "//" ) ) listFinal.add( str ); } } return listFinal } }
In build.gradle
// The following funcationality is coming from a custom plugin that you'll write which will read a text file and create a list. // It'll also ignore any lines that start with "//" import com.mycustom.plugin.gradle.myCustomFileUtil sourceSets { //if you have any //main //test //acceptanceTest //etc } // Read dependency lists from external files List depListCompile = myCustomFileUtil.readIntoList( "$projectDir/dep-compile.txt" ) List depListTest = myCustomFileUtil.readIntoList( "$projectDir/dep-testArtifacts.txt" ) List depListWar = myCustomFileUtil.readIntoList( "$projectDir/dep-war.txt" ) List depListJibx = myCustomFileUtil.readIntoList( "$projectDir/dep-jibx.txt" ) List depListSomeOperationINeed = myCustomFileUtil.readIntoList( "$projectDir/dep-someoperationineed.txt" ) // Define dependencies dependencies { // Compilation compile depListCompile // If dependencies already exist on the local folder / in some workspace compile fileTree(srcDir: "somefolder/whichcontain/myjar", include: "*.jar") compile fileTree(srcDir: "/path/xx/yy/somefolder/whichcontain/myotherartifacts", include: "*.[zw]*") compile fileTree(srcDir: "C:/zzz/somefolder/whichcontain", include: "myotherartifacts/*.[pj]*") // Unit Tests testCompile depListTest // Acceptance tests // Everything from compile and testCompile targets acceptanceTestCompile configurations.compile acceptanceTestCompile configurations.testCompile // Output of compiling "main" files acceptanceTestCompile sourceSets.main.output // Additional dependencies from war and others acceptanceTestCompile depListTest, depListWar // All configuration files acceptanceTestRuntime files( 'conf' ) } // ... and more code here to do other operations
In the dep-compile.txt file you can have entries like
com.mycompany.project:oneofmycompanyartifact1:1.1.1 com.mycompany.project:oneofmycompanyartifact2: 1.0.1@zip httpunit:httpunit:1.6 jibx:jibx-bind:0.10.3.3 jibx:jibx-extras:0.10.3.3 jibx:jibx-run:0.10.3.3 cactus:cactus:1.7.2 selenium:selenium:0.9.2
Similarly, in the dep-testArtifacts.txt file, you can have the following entries (and create similar dep-XXXX files for the phase / Gradle functionality you want: compilation, testing, war, doSomeOperation, etc.).
cactus:cactus:1.7.2 jackson-all:jackson-all:1.9.9 jibx:jibx-bind:0.10.3.3 jibx:jibx-extras:0.10.3.3 jibx:jibx-run:0.10.3.3 //junit:junit:4.10 junit:junit:4.11 mockito-all:mockito-all:1.9.5
source share