Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle parent pom like feature

Tags:

gradle

At my work we use Maven. I am going to try gradle for the first time. We use a common parent pom for all project which has setting for commonly used maven plugins and few comon dependencies. Is there a similar option available in gradle?

My second question is regarding release management. We use maven release plugin, which works pretty good for us. Is there something similar available in Gradle?

like image 277
Murali Avatar asked Mar 18 '13 00:03

Murali


2 Answers

To share stuff within multiple projects of the same build, use allprojects { ... }, subprojects { ... }, etc. Also, extra properties (ext.foo = ...) declared in a parent project are visible in subprojects. A common idiom is to have something like ext.libs = [junit: "junit:junit:4.11", spring: "org.springframework:spring-core:3.1.0.RELEASE", ...] in the top-level build script. Subprojects can then selectively include dependencies by their short name. You should be able to find more information on this in the Gradle Forums.

To share logic across builds, you can either write a script plugin (foo.gradle), put it up on a web server, and include it in builds with apply from: "http://...", or write a binary plugin (a class implementing org.gradle.api.Plugin), publish it as a Jar to a repository, and include it in builds with apply plugin: ... and a buildscript {} section. For details, see the Gradle User Guide and the many samples in the full Gradle distribution.

A current limitation of script (but not binary) plugins is that they aren't cached. Therefore, a build will only succeed if it can connect to the web server that's serving the plugin.

As to your second question (which should have been a separate question), there are a couple of third-party release plugins available, for example https://github.com/townsfolk/gradle-release.

like image 163
Peter Niederwieser Avatar answered Sep 28 '22 21:09

Peter Niederwieser


The io.spring.dependency-management plugin allows you to use a Maven bom to control your build's dependencies:

buildscript {   repositories {     mavenCentral()   }   dependencies {     classpath "io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE"   } }  apply plugin: "io.spring.dependency-management" 

Next, you can use it to import a Maven bom:

dependencyManagement {   imports {     mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE'   } } 

Now, you can import dependencies without specifying a version number:

dependencies {   compile 'org.springframework:spring-core' } 
like image 43
matsev Avatar answered Sep 28 '22 21:09

matsev