Spring Boot War - gradle

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

Related

Suppress maven dependency version suffix in local repository

I have a Spring Boot project that uses SAP Crystal Reports. CR is not published in Maven Central. I imported all of the CR jar files into my Maven local repository. In my projects the jars have the version appended to the jar file name. For one jar file, this causes a runtime error. How can I have that jar not have the appended Maven version?
if you build from source using Maven then you can override the artifact final name in the POM of this project
<finalName>myJar</finalName>
If you run the mvn install manually then you have control of what you store into the Maven repository
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
This is my workaround hack.
The Jar is question is never directly referenced by my project code, it is a runtime library of the Crystal Reports java runtime. I do not need it in the classpath at build time, just in the deployed file built by maven.
My Spring Boot project is deployed as a WAR file so I need to structure my Eclipse Maven project so that the Jar is placed in WEB-INF/lib as a plain web app resource. I do not specify the jar as a maven dependency.
It's a hack because the jar file IS a dependency and SHOULD be specified as a maven project dependency in the pom.xml.
This solves my immediate problem.
I blame SAP for not considering Maven for their Crystal Reports Java runtime.

Artifactory + TeamCity : How to deploy custom JAR?

I am building a maven project within a Docker container as a TeamCity job configuration.
(This is necessary because the maven project builds a JNA library -- so it must be built on a specific distro)
At the end of running the docker container, I'm left with the target folder of the maven module which contains the JAR & associated other files (i.e. class files etc..)
I'm stumped onto now how to get this JAR published to Artifactory? All the integration with TeamCity seems to be if the JAR was built with the maven runner specifically
Usually, you use mvn deploy to build and deploy an artifact with Maven. It is transferred to the Maven repository that you specified in your distributionManagement.
With Artifactory, you can also use the artifactory-maven-plugin for deployment.

How do I create the junit5 maven POM files from gradle?

I'm attempting to build (a fork of) jUnit5.
./gradlew build
produces the JARs, but I also need the pom.xml files that go with the JARs, so I can use the artifacts using Maven. Changes are there is a gradle task configured that does this already in the existing jUnit repo, but which?
Figured it out. Gradle is non-obvious to me ... it is the "maven" plugin.
Invoke:
./gradlew install
which will:
Generate POMs into directory .../build/poms with name pom-default.xml
Copy those (while renaming) and the JARs into the local Maven repository at ~/.m2.

Gradle Spring boot application not executeable after install/uploadArchives

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.

Where do maven jboss plugin deploy

I am using maven and jboss plugin. When I run this command
mvn clean install jboss-as:deploy
I will deploy in currently running jboss but I want to know which jar file it deploy..jar file generated in target folder or jar file in local repository?
By default it gets the bits from target folder. Look at targetDir property of the plugin.
You can find the details in the plugin documentation.

Resources