Gradle: Multi-Project Build with project dependent property

196 views Asked by At

I'm currently trying to create a multi project build with gradle which should produce multiple ear files. All ear files are using a shared ejb project which bundles an ejb-jar.xml deployment descriptor. This deployment descriptor should contain an env-entry which is dependent on the ear-project.

Here is how the project structure looks like:

├───ear-project1
│       build.gradle
├───ear-project2
│       build.gradle
├───ejb-project
│   │   build.gradle
│   └───src
│       └───main
│           └───resources
│               └───META-INF
│                       ejb-jar.xml
├───build.gradle

build.gradle (root)

plugins {
    id 'java'
}

subprojects {
    apply plugin: 'java'
}

build.gradle (ear)

apply plugin: 'ear'

dependencies {
    deploy project(':ejb-project')
}

build.gradle (ejb)

import org.apache.tools.ant.filters.ReplaceTokens

ext {
    placeholder = 'thisShouldBeSetByTheEar'
}

processResources {
    with copySpec {
        from 'src/main/resources'
        filter(ReplaceTokens, tokens: [replaceMe: placeholder])
    }
}

The whole project should be created by one single command, e.g. gradle ear.

So far I've tried to inject the property via a closure, but it does not seem to work:

deploy project(':ejb-project', { placeholder = 'ear-project1' })

How can I configure the ear projects to set the placeholder variable of the ejb project?

You can access the complete example via GitHub: https://github.com/monsieurvader/multiproject-ear

0

There are 0 answers