What is the difference between gradle repository and a maven repository? - maven

I’m trying to create a custom Artifactory repository to resolve dependencies in my gradle project, but I’m confused between gradle and maven repo: what repository key should I choose? And what is the real difference between a gradle repository and a maven repository?

There is no such thing as a Gradle repository.
While Maven is the name for both a build tool and a repository type, Gradle ist just a build tool. It supports both Maven and Ivy repositories.

Gradle is a Java development tool, but not the only one. An alternative is Maven, which is older and commonly used. Spring Framework let developers to choose between these two tools.
Gradle is an open source build automation system that's built on Apache Maven and Apache Ant concepts. It uses a domain-specific language based on the programming language Groovy. This is a very interesting difference between Gradle and older Apache Maven, which uses XML. Gradle was developed in 2007 and in 2013 it was adopted by Google for Android system (this must say a lot about how powerful is Gradle).
Maven Repository is a directory where all the project jars, library jar and plugins can be used by Maven/Gradle easily. Maven Repository are of three types: local, central or remote. Gradle can and use the Maven Repositories, as I've said before, Gradle is build on top of Maven concepts.

You can think of Gradle as goodness of Ant and Maven put together minus the noise of XML. And scriptability with groovy is very big plus.
Gradle gives you conventions but still gives you power to override them easily.
Gradle build files are less verbose as they are written in groovy.
It provides very nice DSL for writing build tasks.
Has lot of good plugins and vibrant ecosystem
When to use Gradle and When to use Maven ?
Almost everywhere for creating java/groovy project. The build files are much terse.
With Google choosing Gradle as the new build system for Android SDK and mature libraries like Spring, Hibernate, Grails, Groovy etc. already using it to power their builds, there is no doubt that Gradle is becoming de-facto build system for the Java ecosystem.

Related

After making a Gradle groovy jar library how to make it re-usable for multiple local projects?

Here I read about how to make a Groovy library .jar ... i.e. pretty much the same as making a Groovy (standalone) project. But I'm not clear what you do then with the resultant .jar...
Say I have two Eclipse "proper"/"standalone" projects (I'm using Groovy for everything) and I want them to share a third Gradle library project of mine as a dependency, which is merely a library of classes... how are my standalone projects expected to find the latest .jar version of the library which they're both using...?
My expectation would be that somehow these versions of the library .jar would have to under GRADLE_USER_HOME (i.e. same location as all other dependency .jars).
Then I would assume that in the build.gradle of both standalone projects you'd have a line like
compile 'mylibrary:mylibrarymodule:3.+'
... of course the first part of these compile directives normally involves a "domain name in reverse" ... and this is normally used by a repository like Maven. How does it work with something which doesn't need to be published?
NB at the time of writing I don't have a Maven account as such and have no idea whether "publication" for re-use of a local common library project like this is essential or not.
Naturally, when I distribute versions of my standalone projects they will need to be packaged up with the library .jar in question.
A link to a how-to for a case like this would be more than welcome: I haven't found it under gradle.org.
If you are developing by yourself, you can use maven-publish plugin to publish your artifacts to local maven repository(you don't have to install maven for this) and on your dependent project you can simply say use mavenLocal repository for dependencies.
If you are on a company, I suggest installing a repository manager and deploy your artifacts to this repository so others can use. You can use their respective plugins to deploy easily. (Gradle Artifactory Plugin, Gradle Nexus Plugin, these are just deployment plugins, you have to setup respository manager to. There are other repository management tools also.) Doing the above process from CI server is the preferred way.
To use latest version of a dependency, you can use Gradle Versions Plugin. If the versioning happen often, using snapshot versions also a possibility.

Edit Java source code before compile

I am new to gradle. I am looking forward to migrating from maven to gradle.
I had few requirements:
Existing project is maven based, and is generating a fat jar/uber jar. I am planning to split this into multiple projects, and creating smaller/thinner jars/libraries
I am currently evaluating the Multi-project Build support.
I have to also edit the Java source code, automatically, like making the java source modifications based on certain conditions
Publish the project as maven based, as other projects which need these split-up jars are still maven based.
I suppose Maven plugin can be used for publishing?
Would Gradle be a good, scalable solution for these two requirements which I am looking into currently?
Also please provide some pointers around these two topics.
Gradle has very good multi-project support, far better than Maven's. You can start with this documentation section
You can setup compilation of generated/auto-edited sources as well. Take a look at this forum post, discussing compilation of sources created from database using hbm2dao
You can setup publishing of projects using the Maven plugin. pom.xml files will be generated automatically

Gradle equivalent for Maven Java formatter that uses com.googlecode.maven-java-formatter-plugin

I'm switching a large project from Maven to Gradle. Existing Maven project uses com.googlecode.maven-java-formatter-plugin to format the Java code. Looked for the equivalent in Gradle. Found https://plugins.gradle.org/plugin/com.github.sherter.google-java-format, but it spewed a bunch of errors out, was really slow, and didn't generate the same output as the Maven plugin.
Also looked here: https://github.com/google/google-java-format - no help.
Is there a Gradle plugin which will give me same result as the Maven plugin?
There is this other Gradle plugin, which uses the Eclipse formatter. Maybe you can tweak it to achieve the same results as with the maven plugin you mentioned (I'm not using this plugin myself).
Note that it is an explicit non-goal of google-java-format and the corresponding Gradle plugin to be configurable. If you are not happy with the formatting style then this tool is probably not appropriate for you.
(if you have technical problems with my Gradle plugin, feel free to provide more details or open a ticket on Github)

Is there any easy way to generate mave pom file from ant build

I have a ant build.xml file , how can i directly create a maven pom.xml which is exactly equivalent of build.xml file ? I know that I can create a maven project and move the folder of build.xml to appropriate folder of maven directories, But is there any automated way of doing this ?
ANT and MAVEN are different so there is probably no such complete automation really.
Still there are some attempts to automate it (see: https://github.com/ewhauser/ant2maven/blob/master/ant2maven.groovy and its forked repositories).
Another approach may be to create a pom.xml file and use https://maven.apache.org/plugins/maven-antrun-plugin/ to include the ANT script in it.
The simple answer is no. There is no easy way to generate a POM.
In my opinion switching to Maven is best left to new projects with little or no legacy to defend. In short Maven is a highly opinionated build tool that follows a standardized build workflow. ANT, on the other, ANT is gloriously configurable... resulting in no two builds working the same way :-)
A secondary problem is that few ANT builds properly record the origin and version of their 3rd party dependencies...
In most cases you are better off keeping the existing ANT build logic and introduce dependency managment using a plugin like Apache ivy. This allows an ANT project to properly integrate with a Maven repository infrastructure. This further enables collaboration with other teams using alternative build tools like Maven, Gradle or SBT.
Related answers:
Migrating complex project from Ant to Maven - How to handle unusual folder structures?
Maven or Ivy? Which one is better with a system already in production? And the other differences?

What can i use for create a dynamic web project in eclipse not using Maven?

i just want use Spring 4 and Hibernate 4. that's because in my company we don't have internet service for Maven or gradle.
If your situation is so sad that you don't have access to any Repository (Maven central nor internal mirror of it), Ant build system (Predecessor of Maven and Gradle) is designed to work with local dependencies.
You would need to download them somehow, push to your source control (hopefully that is available to you) and hook them into Ant.
There is also option to use Bash or Make, but personally wouldn't recommend.

Resources