POM file for integrating Grails with Maven, with dependencies in BuildConfig.groovy - maven

I've got a Grails application as part of a larger Java source bas that's all built with Maven. I'd like to include the Grails app in the Maven continuous integration, nightly builds, etc.
(Ideally I'd also like it to be part of a Maven parent-project hierarchy, so I could pick up live code changes from other projects without having to install them into my local repository. I would also like a pony.)
I tried running "grails create-pom", setting "pom true" in BuildConfig.groovy, and using the POM to manage my dependencies. However, this left me stuck in org.xml.sax.Locator classloader hell. So I went back to using BuildConfig.groovy for my dependencies.
I understand that "pom true" is a recent (Grails 2.1.0) feature, and it should be possible to integrate Grails into a Maven build while still managing dependencies in BuildConfig.groovy. Problem is, I can't find any documentation on what should go into the POM in that case. What do I put in my POM?

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 execute all test case in the “spring-boot” project with gradle?

spring-boot migrated from maven to gradle since 2.3.0.M1, so the question is tagged with gradle. link
What I want to do?
We known, spring-boot-dependencies project is managing lots of jar's version and works well, that's so great! We plan to use spring-boot-dependencies as a basic to manage jar's version in my company. sometimes we need to upgrade some of the jar in spring-boot-dependencies because of vulnerabilities, and this may cause version mismatch between jars.
I have noticed that, there is about 10*000 tests case in springboot project:
So I'd like to modify some jar's version in the spring-boot-dependencies project, and then run all test of spring-boot projects, to help me analyse is there any version mismatch。
What I did?
clone the latest code from github:https://github.com/spring-projects/spring-boot.git
run .\gradlew.bat build(work on windows) in the spring-boot project root directory.
it seems only a few tests get executed:
So, my question is how can I execute all test case in spring-boot project?
Any suggestions would be greatly appreciated!
the path buildSrc/ is for the gradle custom plugin code. You are therefore looking at the build tool test results.
your main code results will be under build/reports/... folder (of each module)

Why third party dependency is required exclusively from OSGi container even if I have it in my maven dependencies?

I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

Grails refresh-dependencies doesn't download snapshot dependency from local maven repository

I am using Grails 2.1.1 and Maven 3.0.3.
In my buildConfig.groovy, I have pom true and I generated the pom.xml via grails create-pom. In this pom I have a dependency with <version>1.0-SNAPSHOT</version> which exists only in my local maven repository. I can successfully run mvn clean compile on this pom.
However running grails refresh-dependencies does not download the most recent version of my snapshot dependency from my local maven repository. The only way I can get it to download the latest version is to manually delete it from the ivy cache.
According to the documentation:
All dependencies (jars and plugins) with a version number ending in -SNAPSHOT are implicitly considered to be changing by Grails.
I assume it would recognize my snapshot file as changing and download it when it is modified. Am I missing some other configuration step? I only want to use maven for dependency management, but is this entirely the wrong way to use Maven with Grails?
This is actually the normal behavior of the Aether resolver.
--refresh-dependencies doesn't bypass your local maven cache. To do that, you'll need to set the maven repository that contains your dependency to always download new snapshots. In BuildConfig.groovy's repositories block:
mavenRepo ("http://my.server/repos/my-grails-plugins") {
updatePolicy 'always'
}
Credit to http://asoftwareguy.com/2013/10/25/grails-2-3-maven-dependency-caching-issues/.
Since I haven't got any responses, what seems like the solution to this is to just not use the grails command line, but rather use the maven goals for Grails.
mvn grails:run-app does the trick. All snapshot dependencies are refreshed and I can start up my app and see the local changes reflected. This way I'm ignoring ivy altogether and letting maven take care of everything.
Edit: If you go this route, I suggest following chapter 5 of the User Guide on Maven Integration for setting up your pom.xml, etc. I was able to follow this and get it set up without any surprises.

Resources