Publishing a Spring Gradle Project as jar - spring

I created a gradle project having common code among all the projects in the same workspace. For this,
I set this new project in class path of all other projects. So it is available at compilation time.
I mentioned package structure of new project in application-context (spring configuration) of all projects. So that the component of new project can be autowired.
In build.gradle of every project, I have addedn an extra entry under dependencies task i.e. compile project(':newproject')
Everything is running fine. Only I need to figure out gradle task to generate jar of new project.
Is it the correct way? Or should I
build jar of new project,
define it as dependency in build.gradle of other projects,
copy it libs folder of other project at the time of deployment.
In 2nd approach, I have no idea how Spring'll autowire the bean of newproject.

Adding the dependencies manual via a build jar file would be strange. I would stay with the "correct" dependencies and try to figure out a way to build the jar of "new project".

Related

Hot reloading a multi-module spring boot application with gradle

I'm trying to convert a project from maven to gradle, but I'm having trouble getting hot reloading to work the same way. I can't show the actual project so I've created two identical very simple projects. One with maven one with gradle. These projects contain two modules:
project
|____api
|____lib
The /api module contains a spring-boot app which depends on code from the /lib module
In the maven project I can change code in either of these modules and recompile either with my IDE (intellij) or with the maven cli and spring-boot-devtools will hot reload the application. However in the gradle version it only successfully hot reloads code that has changed in the /api module.
From what I gathered this seems like a classpath issue. If you run gradle or maven in debug mode it prints out the classpath it passes when it starts the application. Maven includes <project_dir>/lib/target/classes/kotlin/main. However gradle only includes <project_dir>/lib/build/libs/lib.jar
I'm very new to gradle to I might have some of the build configuration messed up. Here are the two project repo's:
Maven: https://github.com/Perry-Olsson/mvn-hot-reload
Gradle: https://github.com/Perry-Olsson/gradle-hot-reload

How to update a jar that used on another project

I have two project.First project's name is studentApp, second one is coursesApp. I have imported two project on eclipse.First project(studentApp) uses courseApp jar as maven dependency.
I implemented a feature on studentApp project but this feature uses coursesApp project's service classes. Therefore, I had to change service classes on coursesApp project. Right now , my student project does not see service classes because jar is 1.0.I used mvn clean install commond on second project and created a new jar 1.0.1.
Now, I changed my pom.xml on first project to change version.I made 1.0.1 I used
mvn clean installbut there is no jar.How can I do now? I think jar is on company repo.Do i have to add a new jar to company repo everytime to make changes?

How do I add a module dependency in gradle.build

I use Intellij Idea. I have a java gradle project with two modules ('main' and 'repo'). I add a dependency in the main module to the repo module, using the "Project Structure" menu. My project builds ok, but when I run a sonarqube task in my project, the module depencency has gone. Is there a way to add a dependency to a module in gradle, so it doesn't disappear?
If you configure your project only in IntelliJ your gradle configuration will not be change because it is an IntelliJ configuration only.
The "normal" way is: first you set your gradle configuration and then just open your project in IntelliJ. Everything will work automagically inside InTelliJ.
Here is the documentation explaining how to add a sub project in gradle.

Run specific project using gradle

I have a Groovy application, I am using Gradle as my build tool. I have 2 seperate projects a Ratpack project with it's own build.gradle file and then a React project with it's own build.gradle file.
When I do ./gradlew run It builds my Ratpack project which in my Ratpacks build.gradle file has
compile project(':react-app')
In the dependencies closure.
Is there a way to just be able to run one of the projects for example ./gradlew runRatPack which stops the React project from being built?
If you can change the following line
compile project(':react-app') which states there is a Project Dependency to
compile name : 'react-app' - artifact dependency, then the project will try to pick the artifact from the repository instead of building the project.
Please let me know if the issue is addressed and this solves your issue.

Building all dependencies in Maven

I have a Ear, war and 2 jar projects in my eclipse.
I want to automatically build 2 jars, war and ear project, when i run the pom inside ear project.
I remember doing this in maven in the past. But i forgot since i lost touch working with Maven for few years now.
Someone please remind me of that..
I used dependency compile, but it is not building jar, when i build the ear directly.
Should i first run pom in jar? does it not build that jar automatically when i build ear?
Create a multi module build that will build it all for you in the reactor. Read more about it e.g. http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-pom-best-practice.html#pom-relationships-sect-multi-vs-inherit
I guess you should define tha .jar and .war projects as dependencies of your .ear project. It is also advisable to have a parent pom, where all the projects are defined as modules, including the .ear project.
In this book you can find a well explained step-by-step setup of a maven multimodule project (with downloadable code).
There is also a great working example of an enterprise multimodule project in the JBoss quickstart examples.

Resources