I'm new to Spring Boot and I'm having some issues combining several sample projects because their dependencies are managed by Maven and Gradle respectively. My goal now is to convert all the Gradle projects (build.gradle) tp Maven (pom.xml) but can't seem to find a suitable tool.
Is there any guide on the steps to accurately convert a build.gradle file to pom.xml or it's simply not possible?
I've searched and tried the maven-publish plugin, and thought it would give a ready-to-use pom.xml but the pom-default.xml generated contained some syntax errors and can't be used for setting up a maven project.
Related
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()
}
}
}
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.
I have a standard spring-boot project with org.springframework.boot:spring-boot-gradle-plugin. i know i can override dependency version with e.g.
ext['slf4j.version'] = '1.7.5'
but how can i get the version currently imported by spring-boot plugin so i can use it later in the script? for example:
currentSlf4jVersion = xxx('slf4j.version')
The dependency management plugin that Spring Boot's plugin applies for you provides programmatic access to the properties in imported boms.
You can get the value of the slf4j.version property like this:
dependencyManagement.importedProperties['slf4j.version']
You can find your gradle project dependencies using command
gradle dependencies
For All:
gradle listAllDependencies
For sub-project:
gradle :<subproject>:dependencies
This will output dependencies
I have a multi-module gradle project that looks something like the following
books
books-api
books-server
books-tests
books-client // generated using 'gradle swagger'
The books-api contains service.swagger.json file that I'd like to use to generate a Java based client using Swagger codegen gradle plugin. The books-test module is a test suite that will use the generated client to run tests agains the server.
The Swagger codegen gradle plugin creates an entire gradle module books-client. Currently, the module is generated by running the swagger task on the root project. I have to perform this step manually before running a gradle build on the root project so that the books-test modules dependency on books-client is satisfied.
Is there anyway to generate books-client and have books-test depend on it for just running gradle build on the root project? I.e. gradle build would generate books-client and build books-test successfully.
Why do you create the whole gradle module dynamically? Or do you mean you just create the source of the module dynamically?
I'd suggest that you do not create the gradle module dynamically, but have it there with all the necessary dependencies and just let the swagger plugin generate the code. As far as I see in the plugin, the swagger task comes before compileJava anyway.
So my suggested workflow would be that you have the gradle module there and then use the standard gradle build workflow. Or are you running into problems with this approach?
I'm developing a plugin for eclipse, but I'm having issue with including dependencies in my project.
Currently I am able to include hardcoded dependencies like specified here: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Feditors%2Fmanifest_editor%2Fdependencies.htm
However, I'd like to include a dependency of a project I've worked on, this way when I make changes to that dependency, I will get the new features in my plugin project.
I really like working with maven pom.xml files, how can I include this in my eclipse plugin project? Or is this even possible? I'd appreciate anyones thoughts or recommendations on this.
You can try to find a Maven plugin on the Eclipse Marketplace, like M2E. See this SO question.