How to convert Gradle to maven in eclipse - java

I want to migrate from gradle to maven I tried and build successfully but I am facing issue while running my application
I took this gradle project https://github.com/spring-projects/spring-security-kerberos from git, its working fine as gradle project.
But my requirement is maven project please tell me how I can do it.

You can try and add the Maven Publishing plugin and its maven-publish in order to generate a pom.xml.
A MavenPublication is the representation/configuration of how Gradle should publish something in Maven format.
You directly add a named Maven Publication the project's publishing.publications container by providing MavenPublication as the type.
publishing {
publications {
myPublicationName(MavenPublication) {
// Configure the publication here
}
}
}

using archiveTask you can generate the pom.xml
http://www.gradle.org/docs/current/userguide/maven_plugin.html#sec:maven_pom_generation

Related

Using Gradle plugin from a custom Maven repository

I'm working within a limited dev environment that uses a private Maven repository. In it is hosted a Gradle plugin that I'm trying to use. However, I don't think it's following the expected naming and directory structure for Gradle plugins, so my build fails when I use the Plugin DSL. In the Maven repository, the plugin is structured as something like:
com.mydomain.project:mydomain-plugin:1.0.0
When I refer to this plugin using the Gradle plugin DSL using the following definition:
plugins {
id 'com.mydomain.project' version '1.0.0'
}
I get an error with my build complaining that it can't find com.mydomain.project:com.mydomain.poject.gradle.plugin:1.0.0. However, there doesn't seem to be a way through the plugin DSL to indicate that the plugin uses a different artifact id pattern. Any ideas how to resolve this?
You can use pluginManagement { } to specify additional repositories for Gradle plugins.
pluginManagement {
repositories {
maven {
url 'https://my-company-maven-repo.com/'
}
gradlePluginPortal()
}
}
See Custom Plugin Repositories
for more details.
That's the first step, second you need to ensure you are publishing two artifacts in order to use the plugins { } DSL:
Plugin Marker Artifact
Gradle plugin JAR itself
Both artifacts are created for you by the Java Gradle Plugin Development plugin. If you are not using the plugin, then you will need to create the plugin marker artifact yourself.

Gradle dependency not working on same version of build

At our company, we use Artifactory to manage artifacts and dependencies of Gradle.
We have library that was build with Gradle 6.0.1, in addition, have a micro-service that was built with Gradle 6.0.1 that is using this library as a dependency.
I verified that this library exists in the declared repo.
When we try to build the project we get an error that this library doesn't exist in the declared repositories and that we should declare the correct one.
The weird part is that if we downgrade the micro-service to Gradle version 5.6.2 the library does get download and working.
We also tested it with other older micro-services that we have based on a template project that is built with Gradle version 4.10.3 and It's also working in them.
What could be the issue?
The library I was referring to in my question didn't have the POM file published with it.
So either I will need to publish it again with the POM being generated (since the library itself was built with Gradle and not Maven - there is a way to generate POM with Gradle)
or:
I will add the following code to build.gradle file so Gradle will download the artifact even though it doesn't have POM file.
repositories {
maven {
url uri('lib')
metadataSources {
artifact()
}
}
}

Build JAR with a dependency from the custom repository

I'm trying to build a JAR artifact which requires a custom dependency from the bintray repository, like:
https://dl.bintray.com/foo/bar
Is it possible to instruct the project that consumes such a library that it should resolve dependencies in the extra repository?
Or should I take another approach to provide it?
TL;DR
Build a fat jar including your dependencies.
Long Version
Yes, it is potentially possible to instruct a project that consumes your Gradle plugin to download plugin dependencies from a non-default repository. But it requires the user intervention which is probably not what you want to hear.
The following settings.gradle should retrieve your plugin from the Gradle Plugin Portal and resolve the dependencies from your Bintray repository:
pluginManagement {
repositories {
maven {
url 'https://dl.bintray.com/foo/bar'
}
gradlePluginPortal()
}
}
This is documented under Plugin Management.
Please note that I'm a bit vague in my answer since I never did something similar. What I can tell is that the spring-cloud-contract plugin does exactly this for snapshot versions.
IMHO, in your specific case, you get the best user experience by building a fat jar that includes your dependencies. A remarkable companion being the Gradle Shadow Plugin. It also features additional functionality for Gradle plugins, should you ever need them.

Maven connection to IDE

I am using Maven to use Postrgres SQL driver. Besides I am using InteliJ IDEA Ultimatre Edition, and, as I understood, Maven is included in Ultimate version initially. Correct me - all I need, is to set dependencies, and connect PostrgeSQL to Java. I am not oblige to Download Maven (except required Dependecie of course, I mean Maven as framework)? Thanks a lot!
When you are creating a new project, choose Maven. After the project is created, you will receive an empty Maven project structure with the pom.xml and a script mvnw of Maven Wrapper, which you can use (instead of mvn) to build your app.
Just add dependencies to the pom.xml and build.
The Maven Wrapper will do the work for you - download Maven into the project subdirectory and use it.

How can i do a gradle publish on teamcity to publish a gradle build that uses the maven plugin?

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.

Categories