How do I create the junit5 maven POM files from gradle? - 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.

Related

How to reference local Gradle project from Maven build as dependency?

I have several Gradle library projects and main Ant spring web-app project (historically). I'd like to replace Ant with Maven for main project while keeping existing Gradle projects nature.
Is it possible to refer local Gradle projects from pom.xml as local dependencies of Maven project?
Search readily gives me the opposite - "how to refer maven projects from gradle builds", but not my case.
Gradle always builds locally build/libs (or distributions); the only easy way to share the build dependencies between completely different projects is 'as maven repository dependencies'
in your case the options are
Work Local Builds only
add the maven plugin to the gradle builds - do local install
and refer them in the maven build locally.
Build Anywhere
Your Gradle builds publish artefacts to your local nexus
and you refer them properly in your dependencies
--
Gradle by default does not have 'maven install'; it can be added using the maven plugin see - https://docs.gradle.org/current/userguide/maven_plugin.html#header.

Gradle Multi-project build - project dependencies and build order

I need to migrate a multi-project build from maven to gradle and maintain the way inter-project dependencies and build order work. I'd like to use the maven plugin in gradle and continue to publish artifacts to both local and remote maven repositories.
The multi-project structure is like so:
root/
--Project-A/
----Project-A1/
----Project-A2/
--Project-B/
----Project-B1/
----Project-B2/
In maven Project-A2 has a dependency on Project-A1. If I run mvn install_ from the Project-A2 directory it will only build/install that project and pull it's dependency on Project-A1 from the local/remote maven repository. If I run mvn install from Project-A it will build/install both Project-A1 and A2 and calculate the build order based on the above mentioned dependency. How can this same behavior be achieved in gradle?
Additionally, Project-B2 has a dependency on Project-A2. If I run mvn install from the Project-B2 or Project-B directories this dependency should be pulled from the local/remote maven repository. If I run mvn install from the root directory it should calculate the build order such that Project-A1 builds, Project-A2 builds, and then _Project-B2 builds.
That build order, as far as I know, isn't exactly possible with gradle. If you're building A2 and A1 has changed, gradle will build A1. If A1 hasn't changed then it won't be built. Same goes for the second scenario.

How to properly remove a dependency in a Maven project

I have a Java Maven project where I have some dependencies defined in the pom.xml file. Recently I decided to move from Junit to TestNG so I deleted the Junit dependency from my pom.xml and added the TestNG one.
I was expecting to see the Junit jar library disappear from the Maven Dependencies folder as a part of the process but that didn't happen. I can still see the jar file in the dependencies folder and it is still being used by my test cases.
I can see TestNG jar is there as well but it's not being used. I can change it manually of course but that wasn't my intention.
Am I doing something wrong are there any additional steps that I missed that will allow me to remove the old dependency?
The following applies for the global .m2 folder where maven dependencies can be downloaded and is common to your maven projects.
the .m2 folder will not clean by itself as those dependencies could be used in another project so its wrong assumption that replacing a dependency in a a pom file will automatically remove from your repo.
you can look at the depedency plugin and run the following
mvn dependency:purge-local-repository
or
mvn dependency:purge-local-repository -DreResolve=false

Compile maven sub-project with gradle

i have a gradle project that need the jars generated by a subproject that uses maven.
Can I automatize the compilation of the maven project through gradle and declare it as a dependency ?
A common solution is to call out to Maven via an Exec task, then collect the Jar(s) from the file system.

tycho plugin + maven-dependency-plugin: copy dependencies from local projects instead repositories

Main Goal: deploy a project as jar and eclipse-plugin
current state: project builds fine as jar package
Now i want to create a second project which wraps the jar project as eclipse plugin
use tycho-maven-plugin to create eclipse-plugin
add the jar of the original project (with copy-dependency)
add an Activator
export packages from jar
create correct MANIFEST.MF
i tried to copy the jar with copy-dependencies bound to create-resources. This works as long the jar is found in repository, but the local project gets ignored.
This results in a build failure since the jar is not found.
Is it possible to tell copy-dependencies to take the jar from the target directory of the project? Or should i use some other method than using tycho?
Edit:
I solved my problem with 4 projects:
normal project (nothing special here)
the wrapper project using tycho maven and copy-dependencies.
bound copy dependencies to some goal before compile (e.g. generate-resources). Excluded all artefactid which were set as dependency in the MANIFEST.MF.
a prepare project, which calls the normal project and installs it into the repo. This is needed because the tycho-maven-plugin is bound to validate and it is not possible to call the exec plugin beforehand (at least not easy).
a multi module project which calls the prepare project before the wrapper project.
Build your local project (which artifact was missed) with "mvm install". It will be deployed in your local repository ($USER_HOME$/.m2/repositories). After this dependency should be resolved.
Alternatively you can "mvn deploy" if you have local company maven repository like Artifactory or Nexus.

Resources