Gradle Spring boot application not executeable after install/uploadArchives - gradle

I want to upload an executable jar/war to a nexus repoistory
When running a gradle build I get a 66 MB jar file containing all required libraries.
However, after running install or uploadArchives, the created jar file now only contains my code and is no long executable.
When creating a war file the only thing missing is Spring's loader package.

The above happens when running gradle tasks separately,
e.g. gradle build
or gradle install
However, if the gradle tasks are run together,
e.g. gradle build install
or gradle build uploadArchives
the executable part is not removed.

Related

How to build gradle project before creating a distribution?

I have a gradle 6.x project, where I use the distribution plugin to create .zip distribution.
https://docs.gradle.org/6.9/userguide/distribution_plugin.html
I use the following command to create a ZIP dist:
gradle distZip
However, I have some jar files that I need to put inside a distribution, and when only running this command, it creates a basically empty zip file, because these jars would be located at /build/... .
How can I tell the distZip task, to build these jars before packaging, preferably without running tests?
Thanks!

Gradle: why assemble task is getting skipped saying it has no actions?

I am trying to do gradle build of spring boot application , when I run the clean build command locally, it internally call few other tasks in which "assemble" is one task, locally it is creating the jars under build/libs folder.
But when this runs on jenkins it says skipping task "assemble" as it has no actions and no jars are produced.

Build and run gradle project on another machine

I have created a project using gradle and have created a gradle wrapper. How can I make sure that the project builds and runs on machine who don't have gradle installed?
If you created the project using gradle (i.e. gradle init), then gradle should have placed a gradlew, or gradlew.bat file in the root directory of your project. Use those files to run gradle on another machine.
gradlew can be used on *nix machines, while gradlew.bat is used on windows.
In any case, gradle also creates a gradle/wrapper which contains the gradle jar, and this can be run on any system which has java installed.
See: Difference between using gradlew and gradle

How to run codes written with maven build in Gradle

if I have created a spring Boot application using maven. Now I have to run the same codes in Gradle,So what all changes I have to make.
Here is the migration guide maven to gradle
A simple project can migrated by following chapter 3
3. Run an automatic conversion
install gradle to you system
run gradle init
Accordig to the same guide:
You’ll find that the new Gradle build includes the following:
All the custom repositories that are specified in the POM
Your external and inter-project dependencies
The appropriate plugins to build the project (limited to one or more of the Maven Publish, Java and War Plugins)

Spring Boot War

I tend to use the runnable JAR during development, but I need a WAR for deployment.
I've followed this article about converting from a JAR to WAR Spring Boot Gradle build.
However, right now, everytime I switch the builds from one to the other, I have to comment and uncomment the specific parts of the build file.
Is there a cleaner way of handling allowing for both a JAR and WAR build?
The war that gets build for deployment (that is if you added the spring-boot maven plugin) is just as runnable as a jar file.
java -jar mywar.war
And presto it starts with an embedded server, you can deploy the same war to your server and then it doesn't use an embedded server.
You can specify pom or gradle build file when you build.
So, you can create multiple pom files (one for jar packaging, the other for war packaging) for maven builds, also do same for gradle builds.
For example, if you setup pom.xml or build.gradle file for jar packaging and also setup pomWar.xml or buildWar.gradle for war packaging, then you can run below command
[ build jar packaging by maven ]
$ mvn clean install
[ build jar packaging by gradle ]
$ gradle clean test bootRepackage
[ build war packaging by maven ]
$ mvn -f pomWar.xml clean install
[ build war packaging by gradle ]
$ gradle -b buildWar.gradle clean test bootRepackage
war file can't be dependency of other project. so if you has other project has dependency on your spring boot project, then that is the case where you want to setup two different build files like above on your build machine

Resources