Java – in a single build Compiling source code with two different sets of dependencies in gradle
I'm using the gradle script. I have two separate cognitive lists and other dependency lists
Listing 1:
cognos:a:10.1.1 cognos:b:10.1.1 cognos:c:10.1.1 cognos:d:10.1.1 com:axis:2.0.3 com:webroot:5.0.3
And Listing 2:
cognos:a:10.2.2 cognos:b:10.2.2 cognos:c:10.2.2 cognos:d:10.2.2 traven:nt:10.5.0 traven:txtx:5.2.1
I need to first compile my source code with list 1 dependencies, then list 2 dependencies, and publish the artifact in the artifact with the following name
Artifacts with list 1 and list 2 dependencies
abc-1.0.0-cognos10.1.1 abc-1.0.0-cognos10.2.2
I can use build Gradle to do it, but I can do it in two separate build Complete in the gradle script I don't know how to build in sign This is achieved in the gradle script Someone knows how to implement it in a single build gradle
apply plugin: 'java' version = '1.0' sourceCompatibility = 1.7 targetCompatibility = 1.7 //create a single Jar with all dependencies task fatJar(type: Jar) { manifest { attributes 'Implementation-Title': 'Gradle Jar File Example','Implementation-Version': version,'Main-Class': 'com.mkyong.DateUtils' } baseName = project.name + '-all' from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } with jar } //Get dependencies from Maven central repository repositories { mavenCentral() } //Project dependencies dependencies { compile 'cognos:a:10.1.1 compile 'cognos:b:10.1.1' compile 'cognos:c:10.1.1' compile 'cognos:d:10.1.1' compile 'traven:nt:10.5.0' compile 'traven:txtx:5.2.1' }
Solution
In build In gradle, replace Cognos and app version with parameters:
version = "1.0.0-cognos${cognosVersion}" sourceCompatibility = 1.7 targetCompatibility = 1.7 ... dependencies { compile "cognos:a:${cognosVersion}" compile "cognos:b:${cognosVersion}" compile "cognos:c:${cognosVersion}" compile "cognos:d:${cognosVersion}" }
Then you can run it manually several times:
gradle build -PcognosVersion=xxxx
If you want to do this automatically, you can write a second gradle driver script, release gradle:
defaultTasks 'performRelease' task performRelease() << { ['10.1.1','10.2.2'].each{ def tempTask = tasks.create(name: "execute_$it",type: GradleBuild) tempTask.buildFile='build.gradle' tempTask.tasks = ['build'] tempTask.startParameter.projectProperties = [cognosVersion: it] tempTask.execute() } }
You can do the following: gradle - B release gradle