Converting a SpringBoot Maven Build to Gradle 6.5, Maven works fine (pre conversion) Gradle BootJar (or even just build) fails with:
[Fatal Error] jboss-parent-12.pom:811:1: Content is not allowed in trailing section.
Why is jboss parent 12 being referenced here? this is an ancient pom, and using --scan does not reveal jboss at all. (--scan dependency list below)
com.fasterxml.jackson.core:jackson-annotations:2.11.0
com.fasterxml.jackson.core:jackson-core:2.11.0
com.fasterxml.jackson.core:jackson-databind:2.11.0
com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.0
com.gradle:gradle-enterprise-gradle-plugin:3.3.3
commons-codec:commons-codec:1.14
io.freefair.gradle:lombok-plugin:5.1.0
io.freefair.lombok:io.freefair.lombok.gradle.plugin:5.1.0
io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE
net.java.dev.jna:jna-platform:5.5.0
net.java.dev.jna:jna:5.5.0
org.apache.commons:commons-compress:1.19
org.apache.httpcomponents:httpclient:4.5.12
org.apache.httpcomponents:httpcore:4.4.13
org.springframework.boot:org.springframework.boot.gradle.plugin:2.3.1.RELEASE
org.springframework.boot:spring-boot-buildpack-platform:2.3.1.RELEASE
org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE
org.springframework.boot:spring-boot-gradle-plugin:2.3.1.RELEASE
org.springframework.boot:spring-boot-loader-tools:2.3.1.RELEASE
org.springframework.boot:spring-boot-parent:2.3.1.RELEASE
org.springframework:spring-core:5.2.7.RELEASE
org.springframework:spring-jcl:5.2.7.RELEASE
org.testcontainers:testcontainers-bom:1.14.2
Alternatively, is there a way to ignore it? BootJar does not generate a jar even with
plugins {
id 'java'
id 'application'
id 'io.freefair.lombok' version '5.1.0'
id 'org.springframework.boot' version '2.3.1.RELEASE'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
enabled = true
}
application {
mainClass = 'my.main.class.MyApplication'
}
Not an expert in build tools but you can proceed with the below steps :
gradle clean build
or Can explicitly exclude the dependency :
configurations.all {
exclude group: "org.jboss", module: "jboss-parent"
}
I hope this will help you.
Related
With the following gradle file within a multi project or multi module build, (lets call it web)
plugins {
id 'groovy'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
dependencies {
implementation "org.codehaus.groovy:groovy:2.5.14"
implementation(project(':persistence'))
}
I'm unable to resolve the class files present in the project 'persistence' and get the following error while compiling
unable to resolve class XXX
This is the gradle file of the 'persistence' module
plugins {
id 'groovy'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
dependencies {
implementation "org.codehaus.groovy:groovy:2.5.14"
}
What could be the problem?
Also, here is the settings.gradle and directory structure
// settings.gradle
pluginManagement {
plugins {
id 'org.springframework.boot' version "2.3.3.RELEASE"
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
rootProject.name = 'gradle-bug'
include 'commons'
include 'persistence'
include 'security'
include 'web'
When gradle sees a "implementation" dependency on a project, it uses the jar of that dependency for compilation.
When you add the org.springframework.boot plugin, it by default disables the jar creation task for that module, but gradle continues to depend on that jar for its compilation, even though the classes of that module have been generated in the build/classes folder.
To fix this, you have to enable the jar creation by adding the following snippet to the persistence module
jar {
enabled = true
}
I've done web search for "plugin request for plugin already on the classpath must not include a version site:stackoverflow.com" and found nothing that particular. Search for "plugin request for plugin already on the classpath must not include a version" (w/out SO) found:
https://discuss.gradle.org/t/error-plugin-already-on-the-classpath-must-not-include-a-version/31814 where I've read in answers e.g.:
I didn’t find any reference to this use case in Grade plugins
documentation.
The error
Build file '/Users/username/github/OpCon/app/build.gradle'
line: 4 Error resolving plugin [id: 'com.android.application',
version: '3.4.1']
Plugin request for plugin already on the classpath must not include a version
appears in IntelliJ IDEA, build.gradle (OpCon):
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle:
plugins {
id 'com.android.application' version '3.4.1' apply true
}
... and then other stuff
I don't understand, classpath 'com.android.tools.build:gradle:3.5.2' does not seem to include 'com.android.application'...
"classpath" has only one occurrence if searched in the project.
ADDED:
Interestingly on https://maven.google.com/web/index.html I can find 'com.android.tools.build:gradle:3.5.2' but no 'com.android.application' branch.
ADDED 2:
I've downloaded (quite many files actually was downloaded for some reason) by command taken from here How can I download a specific Maven artifact in one command line?:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl='https://maven.google.com/' -Dartifact='com.android.tools.build:gradle:3.4.1'
found path com.android.tools.build:gradle in file manager and looked inside only jar there:
username$ jar tvf /Users/username/.m2/repository/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar | grep application
1115 Wed May 01 20:30:18 MSK 2019 com/android/build/gradle/internal/tasks/ApplicationIdWriterTask$applicationIdSupplier$1.class
55 Wed May 01 20:29:18 MSK 2019 META-INF/gradle-plugins/com.android.application.properties
So there is a mention gradle plugin com.android.application in jar META-INF.
File com.android.application.properties is one liner: implementation-class=com.android.build.gradle.AppPlugin.
Web search for "implementation class java" finds info on interfaces. In wiki https://en.wikipedia.org/wiki/Interface_(Java):
An interface in the Java programming language is an abstract type that
is used to specify a behavior that classes must implement.
So gradle plugin could be an interface? How can I dig in further?
Gradle doesn't allow multiple versions of a plugin to be present on the classpath. So if you have a multi module build, there could be a chance that more than one module has declared the same plugin with a different version.
To fix this, you will need to specify a single version in a single place i.e settings.gradle
For example, you will put the following in settings.gradle
pluginManagement {
plugins {
id 'org.springframework.boot' version "2.3.3.RELEASE"
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
}
And then in the individual module gradle files, you will do the following (no version mentioned)
plugins {
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
Just for the record, the error mentioned in the question may also show up with this message
plugin was loaded multiple times in different subprojects, which is
not supported and may break the build
I was facing same problem, I was using spring boot with plugins as follows
plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'war'
}
Since this plugin was present in one dependency gradle was complaining about it. I simply removed those dependencies and it worked:
plugins {
id 'java'
id 'war'
}
Put configuration into build.gradle in the root project with apply false.
plugins {
id 'org.springframework.boot' version "2.5.1" apply false
id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false
}
Then you can just put it everywhere without the version
plugins {
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
More information:
->Example 3. Applying plugins only on certain subprojects
I am trying to build a Spring Boot/Gradle project and create a jar without a main class. My purpose is that this project is a library that will be pulled in by other projects therefore the library project does not require a main class to run. Unfortunately, no matter what kind of gradle config I write I keep getting errors when I try to build install about not having a main class or not being able to find the bootJar task.
Here's what my gradle file looks like:
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE' apply false
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}
repositories {
mavenCentral()
}
jar {
enabled = true
}
bootJar.dependsOn fooTask
But when I run this I get the following error:
Could not get unknown property 'bootJar' for root project
'foo-library' of type org.gradle.api.Project.
What in my configuration needs to change?
Disable bootJar in your build.gradle
bootJar {
enabled = false
}
Spring boot makes it really easy to setup a simple app.
But it takes me longer to actually get a jar file which I can upload to a remote server.
I am using IntelliJ, no command line, and I use gradle. The application is running somehow out of Intellij. But where are the created files? Where is my jar from Bootjar?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
testCompile("org.springframework.boot:spring-boot-starter-test")
// add spring data repos
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql:42.2.4")
// REST interface
compile("org.springframework.boot:spring-boot-starter-data-rest")
// Security
compile("org.springframework.boot:spring-boot-starter-security")
}
Update: Added a picture of the project structure:
Update 2: Folder structure:
There will not be a jar created if you are just running this in your IDE. In order to do that, you need to run the gradle build (in your case) either from your IDE or the command line to get it to build it into a jar.
From the command line, go to your project directory and type this:
./gradlew build
This executes the gradle wrapper, which should download everything you need to run the build, and then executes the build.
You will then find your jar in build/lib
build/libs (if you've ran build to build the jar file)
I am trying to get the Gradle Maven Publish Plugin to publish a snapshot version of my Java library to my local Maven repo such that:
The version of the jar is 1.0.0.SNAPSHOT-<timestamp>, where <timestamp> is the current system time in millis (similar to something like System.currentTimeInMillis()); and
I log to STDOUT/console the full name of the jar being published, including the version above; and
A properly-formatted pom.xml is published to Maven local alongside the jar, so that any other Gradle/Maven projects can "pull it down" locally and fetch its transitive dependencies properly
My best attempt so far:
plugins {
id 'java-library'
id 'maven-publish'
}
dependencies {
compile(
'org.hibernate:hibernate-core:5.0.12.Final'
,'com.fasterxml.jackson.core:jackson-core:2.8.10'
,'com.fasterxml.jackson.core:jackson-databind:2.8.10'
,'com.fasterxml.jackson.core:jackson-annotations:2.8.0'
)
testCompile(
'junit:junit:4.12'
)
}
repositories {
jcenter()
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group 'com.me'
jar {
baseName = 'my-lib'
version = '1.0.0-SNAPSHOT'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
However, with this setup, when I run ./gradlew publishToMavenLocal:
I do see the jar being deployed to ~/.m2/repository/com/me/my-lib/ but without a pom.xml and no 1.0.0.SNAPSHOT version appended to it
I don't even know how/where I would append the timestamp onto the version
I don't even know how/where I would do a println(...) to report the full name of the jar being published
Any ideas?
Regarding #3, To install your artifact to a local repository you do not need the maven-publish plugin, rather the maven plugin
See The Maven plugin documentation, specifically the Tasks section and the Installing to the local repository section with it, you can run gradle clean build install
It works for me with a build.gradle file as simple as this
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
Note, if you need to publish something other then the default generated jar then you need to change the archives configuration
Regarding #1 appending the timestamp, move the version line outside the jar clause and change it from
version = '1.0.0-SNAPSHOT'
to
version = "1.0-SNAPSHOT-${System.currentTimeMillis()}"
This is using Groovy GString (AKA string interpolation - note the change from single quotes to double quotes) to append the current time in millis to the version
Last but not least, regarding #2 printing the jar full name append the following to the build.gradle file
install.doLast {
println jar.archiveName
}
Essentially we're appending to the install task (the one executed in the top of my answer) a println of the jar configuration's archiveName (see here if you want something else)
So all in all my build.gradle file looks like this:
group 'com.boazj'
version "1.0-SNAPSHOT-${System.currentTimeMillis()}"
apply plugin: 'java'
apply plugin: 'maven'
install.doLast {
println jar.archiveName
}