Our gradle build for an EAR looks like this:
plugins {
id 'com.github.jk1.dependency-license-report' version '2.0'
}
apply plugin: 'java-library' // add java and jar tasks
apply plugin: 'war' // add war archive task
apply plugin: 'ear' // add ear archive task
apply plugin: 'eclipse' // build the eclipse classpath
group 'my'
version = findProperty( 'buildVersion') ?: '14.0'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
//optionally provide a static name for the archive, else stick with the convension
def myArchiveName = findProperty( 'earFile') ?: "${group}-${version}.ear"
// some more defines...
sourceSets { // define path for main source set
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
}
}
configurations {
compileOnly.transitive = false // provided by server or product
compileClasspath.transitive = false
warweb // zip artifacts for web overlay
ecj // for eclipse compiler dependency
}
dependencies {
compileOnly(
// provided by server
)
// additional compile+runtime jars
// my artifacts added as overlay of war
warweb "my:my-core-web:$version" changing true
warweb "my:my-extra-web:$version" changing true
deploy fileTree( dir: "$buildDir/libs/", include: '*.war') // add war to ear
//FIXME how to solve in gradle 8+?
earlib configurations.runtimeClasspath // add runtime dependencies to ear/lib dir
ecj 'org.eclipse.jdt:ecj:3.32.0'
}
//build custom jar
jar {
archiveBaseName = "my-$custom"
into 'META-INF', { from 'conf/jar' } // add custom deployment descriptors if any
}
war { // war with product and custom artifacts
dependsOn jar
from configurations.warweb.files.collect { zipTree( it) } // overlay product web content (html/js) from zips
archiveFileName = 'web.war'
classpath = jar // add custom jar output (if any) to WEB-INF/lib
//add my-* product jars to war classpath
classpath += configurations.runtimeClasspath.filter { it.name.startsWith( 'my-') }
}
ear { // ear with product sources and libs
dependsOn war, versionTxt
archiveFileName = "${myArchiveName}"
deploymentDescriptor { webModule( 'web.war', 'my') }
into 'META-INF', { from "$productDir/conf/ear" }
exclude 'my/**' // else my sources are included in ear root
rootSpec.exclude 'my-*.jar' // else my jars are added again to ear/lib
}
So we build a jar, then include jar and the related product dependencies (additional jars) in the war.
Additional (non-product) dependencies are then put in the earlib
via earlib configurations.runtimeClasspath
Trying to run the build with Gradle 8+, we are seeing:
* Where:
Build file '/code/product/parent/build.gradle' line: 98
* What went wrong:
A problem occurred evaluating project ':parent'.
> Adding a Configuration as a dependency is no longer allowed as of Gradle 8.0.
I understand that configuration is no longer allowed, but I am not sure how to configure earlib
to inlcude my dependencies in a similar way?