Building Maven sub-modules in a Gradle project - maven

I have a Gradle build working for a bunch of Java and C sub-modules. I would like to add several sub-modules which are incoming from existing code base and are already setup as Maven builds. Is there a way for Gradle to pickup the Maven sub-modules as part of the parent build?

It seems, there is no native way to run some maven goal within gradle build script. By the way, it is possible to run a maven goal, just providig a custom task of Exec type, which will run a maven build as a command line process. You can read more about this task type here.
Furthermore, it is even possible to provide the maven goal artifacts as dependencies for the gradle project, after you build them from custom gradle task and specify the file-dependency with builtBy property. You can read about it in the official user guide.

Related

Is there any way i can see the effective build configuration of a sub project in gradle (in intelij)?

I have a root project and few sub projects.
The root project, in it's build.gradle file, adds some configurations, tasks, plugins and dependencies to subprojects.
In the subprojects's build.gradle file i have added additional deps, plugins, task and conf.
Now i want to know the effective build configuration of the subproject. Is it possible to get this info using any gradle command. If yes, is the same possible in intellij idea
(In maven I can get the effective configuration of any project using mvn help:effective-pom no matter if it's a submodule or has a parent pom. And in intellij idea i can right-click on the pom and choose to view the effective pom. It's quite simple. )
Edit:
Like Rob mentioned in comments - The below commands can be used to find any projects (parent or child/sub-project) dependencies in various scopes/configuration.
/gradlew :<sub-project-name>:dependencies
and
./gradlew :<sub-project-name<:dependencies --configuration <name-of-configuration>
And the Maven equivallent of the above would be mvn dependency:tree.
But I am interested in knowing other info also besides dependencies. Other info like: tasks, plugins, repositories etc that is applicable for the sub-project (i.e defined in the sub-project + inherited or applied from/by parent project.
maven mvn help:effective-pom == gradle ????

can you build a maven project inside of a gradle wrapper

It may be just that I have a general misunderstanding how gradle build works, but it feels to me that I can not build a maven file inside of a gradle build. Since gradle uses the gradle.build file, and maven uses a pom.xml, it does not seem as though I can do this. I have multiple maven projects that I would like to wrap up with a gradle wrapper. I can not find ANYTHING on whether this is even possible.
Both Maven and Gradle are build tools and you should only use one of them for a given project.
If you have existing Maven projects and like the functionality provided by the Gradle wrapper, there is a similar wrapper for Maven (note that this is currently a third-party plugin but they plan to include it in the upcoming release 3.7 of Maven).
Alternatively you could convert your projects entirely to Gradle.

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.

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.

IntelliJ: How do I run a certain maven goal before building a certain artifact?

So, I know how to run a maven goal before/after make and before running/debugging a configuration. Sweet.
But I would like to run a maven goal before a certain artifact is built and just cannot find the option. The artifact configuration dialog allows to run an ant target, but I have no ant targets, just maven goals.
So, what do I do?
You have 2 options here:
Submit a feature request to support Maven in addition to Ant in Artifact pre/post-processing.
Write Ant task with exec that will run your Maven goal and use it.

Resources