Is there a maven plugin available which calls gradle?
It might sound strange, but my company still uses maven and I want to make some experiments with gradle on our jenkins server. :-)
Related
I have teamcity currently configured to use the maven mojo, to publish the gradle jar as a nexus snapshot with just the gav.
I observe that if i use the maven plugin and do a gradle install in the IDE, i am able to see the generated pom.
1) Can i use this pom to publish the jar in nexus repo in teamcity ? I know that i can do it for a pure maven build by using it's pom.
2) Is there a way to not use this pom, and istead configure teamcity build steps to publish from gradle build directly ?
Gradle can of course take care of the publication. It will leverage the build information to produce a POM file that represents best what is declared in your project.
It will then be trivial to invoke that Gradle task from the Teamcity build.
Have a look at the publishing documentation for details on how to set it up.
What is the exact dependency I need to develop a Gradle Plugin in Java? Ideally I would like to get it from a well-known repository such as Maven Central or similar.
I have a Maven project with a core functionality and I just added two extra plugins, one for Ant, one for Maven. They are already tested and working; easy! Now, I wanted to add a third module for a Gradle plugin to make this functionality also available from any Gradle project.
However, I can't find the exact dependencies I need to develop a Gradle plugin.
The Gradle docs (such as https://docs.gradle.org/current/userguide/java_gradle_plugin.html) are not very well written to say the least. They mention:
the gradleAPI() dependency
or the java-gradle-plugin dependency
But they are quite unclear... no group, no version (really?).
If anyone can enlighten me to where I can get these dependencies from, I would be very thankful.
Gradle's public and internal APIs, aka gradleApi(), are bundled with the Gradle distribution and not independently published and therefore not easily consumable by Maven builds. There's the pending epic #1156 (Ensure plugin cross-version compatibility by allowing a user to depend on gradlePublicApi()) that might help here.
Since Gradle plugins are best to be built with Gradle, a pragmatic solution is to invoke the Gradle build from Maven and attach the produced artifact to the Maven build. Andres Almiray (aalmiray) once described this in the blog post Running Gradle Inside Maven (Web Archive Link). He describes the following high level steps:
Create a new Maven module (e.g. gradle-plugin) and add attach it to the parent POM
In the POM of gradle-plugin add a dependency to your core module. Use the maven-dependency-plugin to store dependencies to the Maven build folder, e.g. target/dependencies.
Create the build.gradle, add a Maven repository that points to target/dependencies (step 2) and let it depend on the core module as well as gradleApi(). Implement the Gradle plugin.
Use the exec-maven-plugin to invoke the Gradle build.
Use the maven-resources-plugin to copy the Gradle built plugin jars to the standard Maven build folder.
Use the build-helper-maven-plugin to attach the copied jars to the Maven build.
Sample project to be found here (gradle-in-maven).
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project
In here it is mentioned that it is gradleApi() and I know that this works (from experience). The localGroovy() on that page is only needed if your plugin code uses groovy (does not apply if you only use groovy in the build.gradle of your plugin).
java-gradle-plugin is a library that makes it a bit simpler to make plugins, it is not required though. I personally prefer using gradleApi only.
EDIT:
It appears I've misunderstood the question. Here are the steps to get gradleApi jar:
Create a Gradle project with your desired Gradle version.
Add implementation gradleApi() dependency.
Import/run the project once.
Go to your .gradle folder (located in home folder in Linux-based operating systems).
Open caches folder
Open the version folder you want, e.g. 6.0.1
Open generated-gradle-jars folder.
Copy the jar to wherever you want and use it.
For me the 6.0.1 jar is at ~/.gradle/caches/6.0.1/generated-gradle-jars/gradle-api-6.0.1.jar
Please note that I have not tested this, I know the jar is there but I haven't tried using it.
A philosophic question with Maven in continuous integration.
In Maven we had the famous command mvn release:release to release the project. This changes the release in the pom.xml.
Now, we use continuous integration/deployment, is there always any utility to release the project with the Maven way?
Your question could be reworded better but see this maven release plugin. Releasing a project is made in two steps: prepare and perform.
Maven Release Plugin
We already started our project in mavens(spring mvc) but realized gradle is better for managing big to enterprise level builds like our project. Is there a way to keep mavens but also add on gradle to the same build?
And if yes, how would I add gradle to my existing maven project? thanks.
I guess you need to make a decision:
Invoke maven from gradle
Invoke gradle from maven
If your end goal is to move to gradle then I suggest invoking maven from gradle. It looks like there's a plugin here which will do the job
I have a project with a complicated ant build that we would like to remain as ant at the moment (will be converted to maven eventually).
I am using jenkins at the moment to build/test our application. After build/test, I now want to push the built artefact to a Nexus repository.
For a Maven project, I can use the post build action "Deploy Artefacts to Maven Repository" to do this.
Whats the best way to structure my Jenkins jobs to achieve an ant build and then deploy the code to Nexus?
Have you seen the example Ant scripts in the Sonatype website?
They actually include pushing artefacts to Nexus:
http://central.sonatype.org/pages/apache-ant.html#signing-and-deployments-using-the-maven-ant-tasks
Or there is also some more docs at Sonatype:
http://books.sonatype.com/nexus-book/reference/staging-deployment.html#staging-ant