gradle subProject configuration dependencies not being add to war - gradle

I have a main project that depends on 2 subProjects. All 3 projects have a custom configuration called server.
When I have the following war task, only the dependencies in the main project configuration.server are being added to the war.
task fatWar(type: War) {
archiveName = "arms-fat.war"
classpath configurations.server
classpath configurations.compile
}
How do I add the subProject server configuration dependencies to the war?
EDIT:
Here are some snippets of my build files for context.
rootProject build.gradle
configurations {
server
}
dependencies {
server 'org.glassfish.jersey.media:jersey-media-multipart:2.22.2'
...
}
task fatWar(type: War) {
archiveName = "arms-fat.war"
classpath configurations.server
classpath configurations.compile
}
subProject build.gradle
configurations {
server
}
dependencies {
server 'mysql:mysql-connector-java:5.1.38'
...
}
When I run the fatWar task, the mysql-connector.jar, among others are not bundled in the war

Actually, "classpath" is a property, not a method, so replace the two assignments with a single one, whose value is "configurations.server + configurations.compile".

I was able to solve this (thanks to the link David provided) with the following:
subprojects.each { subproject -> evaluationDependsOn( subproject.path ) }
task fatWar(type: War) {
archiveName = "arms-fims-fat.war"
subprojects.each { subproject ->
project.configurations.server.dependencies.addAll(subproject.configurations.server.dependencies)
}
classpath configurations.server
classpath configurations.compile
}

Related

Gradle implementation project throws exception

I have this hierarchy to my project:
- project
- project-server
- build.gradle
- gradle.properties
- settings.gradle
- project-client
- build.gradle
- gradle.properties
- settings.gradle
- build.gradle
- gradle.properties
- settings.gradle
In the parent build.gradle file I added these lines:
project(':project-client') {
dependencies {
implementation project(':project-server')
}
}
and I am getting:
What went wrong: A problem occurred evaluating root project 'project'.
Could not find method implementation() for arguments [project ':project-client'] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is my entire build.gradle:
apply plugin: 'java'
println(subprojects.each {it -> it.name})
project(':project-client') {
dependencies {
implementation project(':project-server')
}
}
allprojects {
group = 'com.test'
repositories {
mavenLocal()
maven {
//local nexus config
}
mavenCentral()
jcenter()
}
}
subprojects {
version = {version}
}
This is the setting.gradle:
rootProject.name = 'project'
include 'project-server', 'project-client'
Please help, thanks in advance.
implementation configuration is added by the java plugin.
You've applied java plugin only for the root project, in the provided build.gradle. Your :project-client subproject does not inherit plugins from it's parent (root), so the java plugin was not applied to :project-client project.
That's why it "could not find method implementation() for arguments...". Make sure to apply java plugin to subprojects.

How Do I Publish A Renamed bootJar?

I am in a gradle 4.10 Spring Boot project called rest and in my build.gradle I have renamed the boot jar that is created by adding
bootJar.baseName = 'myprefix-rest'
When I run ./gradlew bootJar it creates a file called myprefix-rest-0.1.jar as expected.
However, when I add the maven-publish publish plugin and try to publish, it publishes the file called rest-0.1.jar
publishing {
publications {
bootJava(MavenPublication) {
artifact bootJar
}
}
repositories {
maven {
url = "$buildDir"
}
}
}
Why is it not picking up the baseName?
Why is it not picking up the baseName?
From the MavenPublication docs,
The default Maven POM identifying attributes are mapped as follows:
groupId - project.group
artifactId - project.name
version - project.version
so the actual file name of the boot jar file is not being used. You can overrride the artifactId,
publishing {
publications {
bootJava(MavenPublication) {
artifact bootJar
artifactId bootJar.baseName
}
}
..
}

Unexprected behaviour making EAR for multiple spring boot war's returns a 1k EAR

I need to pack all microservices made with Spring Boot into one big EAR.
The project is organized like this:
/root
build.gradle
settings.gradle
/project1
build.gradle
...
/project3
build.gradle
...
/project3
build.gradle
...
The root settings.gradle contains:
rootProject.name = "mysystem"
include("project1")
include("project2")
include("project3")
The build.gradle in root contains
apply plugin: 'ear'
allprojects {
group = 'de.example'
}
dependencies {
deploy project(path:':project1', configuration:'archives')
deploy project(path:':project2', configuration:'archives')
deploy project(path:':project3', configuration:'archives')
}
ear {
deploymentDescriptor {
applicationName = "myproject"
initializeInOrder = true
displayName = "My Project"
description = "My Project EAR"
}
}
The project build.gradle looks like
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
defaultTasks 'bootWar'
repositories {
mavenCentral()
// Maven Spring Repository for Milestone Releases (optional for development but don't use it in Production)
maven { url 'https://repo.spring.io/libs-milestone-local' }
// Maven Spring Repository for Stable Releases
maven { url 'https://repo.spring.io/libs-release-local' }
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.RELEASE'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter") {
}
compile('org.springframework.boot:spring-boot-starter-json')
compile("org.springframework.boot:spring-boot-starter-web") {
}
providedCompile('org.springframework.boot:spring-boot-starter-tomcat')
}
When I run gradle bootWar per project it generates the WAR in build/lib per project.
But when I run gradle ear in the root project, the output is like this:
Working Directory: D:\Workspace\root
Gradle User Home: D:\Workspace\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3
Java Home: C:\Programme\Java\jdk8
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: ear
Parallel execution with configuration on demand is an incubating feature.
:project1:compileJava
:project2:compileJava
:project3:compileJava
:project1:processResources
:project1:classes
:project1:war SKIPPED
:project2:processResources
:project2:classes
:project2:war SKIPPED
:project3:processResources
:project3:classes
:project3:war SKIPPED
:ear
BUILD SUCCESSFUL in 2s
7 actionable tasks: 7 executed
The result is an EAR with 1k size. There is no WAR generated per project. When I run gradle bootWar on every project and then run gradle ear, it works and the resulting EAR has 130Mb and includes all WARs.
Is there a way, that I only need to run gradle ear and it generates the WARs from bootWar?
In a gradle Spring Boot project the "war" task is disabled in lieu of the "bootWar" task.
Setup the "ear" task in the parent build.gradle to depend on the "bootWar" task(s).
ear {
dependsOn ':project1:bootWar'
}

Gradle publishing - add testCompile dependencies to ivy.xml

When I have the publishing section below in my build.gradle I'll get my ivy.xml descriptor file filled with dependencies as desired. So far so good.
Question: How can I archive it so that the publishing task will also add the testCompile dependencies from my build.gradle dependency section to my ivy.xml file?
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier "source"
}
publishing {
publications {
jarAndSources(IvyPublication) {
from components.java
artifact(sourceJar) {
type "source"
extension "src.jar"
}
}
}
repositories {...}
}
Do I need to specify some sort of a configuration?

build.gradle to pom.xml conversion

I have following code in build.gradle:
task javadocJar(type: Jar, dependsOn: 'javadoc') {
from javadoc.destinationDir
classifier = 'javadoc'
}
task sourceJar(type: Jar, dependsOn: 'classes') {
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts {
archives javadocJar
archives sourceJar
}
When I try building pom.xml it only includes the dependencies in it. I want to generate a pom.xml which can execute all these tasks automatically when i do mvn install. These tasks are already defined by maven as it goals. How can I achieve this?

Resources