Use the gradle bootJar instead of jar task and build fails in Jenkins
Unless you explicitly define the name of the project, Gradle will use the directory name as the project name. On Jenkins, the project directory is called "workspace". artifactoryPublish
is presumably using the project name to determine the name of the JAR file to publish. That's not good practice if that's the case.
Anyway, you really should set the name of your project. You won't have to explicitly set baseName
on the Jar
tasks then. Simply add a settings.gradle file in the root of the project, i.e. next to the build.gradle file, and set its content to:
rootProject.name = "my-project"
That should hopefully fix the problem, although it really depends on what the artifactoryPublish
task is doing.
Simo
Updated on July 09, 2022Comments
-
Simo almost 2 years
After I started using the spring boot gradle plugin in my gradle.build file, the build fails on jenkins.
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
Things work fine locally including build, test and webapp runs fine with Jetty. The only problem is the build fails on Jenkins in the task
artifactoryPublish
. It says:File '/var/lib/jenkins/jobs/release-my-project/workspace/build/libs/workspace-0.2.1-SNAPSHOT.jar' does not exists, and need to be published!
Not sure what's going with the gradle
artifactoryPublish
task. I think the task comes from Jenkins.Before using the spring boot gradle plugin, my jar task in gradle.build is as follows:
jar { baseName = 'my-project' from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } manifest { attributes 'Main-Class':'com.example.Application' } // Exclude manifest signature files exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/LICENSE' }
Since the spring boot gradle plugin disables the jar task, and replaces it with the bootJar task, so I configured the bootjar task as follows:
bootJar { baseName = 'my-project' mainClassName = 'com.example.Application' // Exclude manifest signature files exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/LICENSE' }
One thing I noticed from jenkins log is that it says the file
workspace-0.2.1-SNAPSHOT.jar
does not exist. Seems like it is looking for the wrong file. Previously, it looked for the correct filemy-project-0.2.1-SNAPSHOT.jar
. When I built locally, this jar file was created. Not sure what made jenkins look forworkspace-0.2.1-SNAPSHOT.jar
. It is supposed to bemy-project
as I did define baseName inside the bootJar task.Any idea what's wrong here? Thanks.