I am using a multi-project build. I want to be able to take the JPA entities from one project and expose them as a compile dependency library in another project.
Here is an example what I have right now.
projectA/build.gradle
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
dependencies {
compile project(path: ':projectB', configuration: 'domains')
}
project(':projectB') {
configurations {
domains
}
dependencies {
compile project(':projectC')
}
task domainsJar(type: Jar) {
baseName = 'projectB-domains'
from sourceSets.main.output
from project(':projectC').sourceSets.main.output
include('projectB/domains/**')
include('projectC/domains/**')
}
artifacts {
domains domainsJar
}
}
I modeled this after https://docs.gradle.org/4.1/userguide/multi_project_builds.html - Example 26.26
It works as expected for building the project with gradlew clean build
. The custom library (domainsJar) is contained within the resulting lib dependencies. This approach, however, adds :projectB
as a project dependency to :projectA
when it builds the classpath with the eclipse-wtp
plugin. This makes all of the classes within :projectB
accessible to :projectA
within Eclipse.
Is there a way to tell the eclipse-wtp
plugin to build and wire up the custom jar instead of adding the whole project as a dependency?
I think the solution is to build the domainsJar
and add it as a compile file
as opposed to a compile project
. I don’t quite know how to do that though. Can anyone provide an example of this or think of a better way to solve my problem? Sorry if this is a duplicate question, I googled a bunch, but came up empty.
I am using Gradle 2.12.
Thank you.
UPDATE:
I came up with an approach that seems to work. (at least partially)
projectA/build.gradle
task domainsJar(type: Jar, dependsOn: clean) {
baseName = 'projectB-domains'
from project(':projectC').sourceSets.main.output
from project(':projectC').sourceSets.main.output
include('projectB/domains/**')
include('projectC/domains/**')
}
task copyDomainsJar(type: Copy) {
from domainsJar
into 'lib/domains'
}
eclipseClasspath.dependsOn copyDomainsJar
dependencies {
compile fileTree(dir: 'lib/domains')
}