Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Maven <parent> in Gradle?

On a maven project I have the tag:

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.BUILD-SNAPSHOT</version>
    </parent>

What is Gradle's syntax for that?

This is my build.gradle currently. Im thinking this would need to be added on the build script, maybe replacing what I currently have. If possible, please explain why I would need to add it. I am trying to translate a pom.xml to gradle.

buildscript {
    ext {
        springBootVersion = '1.5.9.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE")
    }
}

plugins {
    id 'org.springframework.boot' version '1.5.9.RELEASE'
    id 'java'
}


repositories {
    mavenCentral()
}

/*Runtime dependencies*/
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile("io.springfox:springfox-swagger2:2.6.1")
    compile("io.springfox:springfox-swagger-ui:2.6.1")
    compile('org.springframework.boot:spring-boot-starter')
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
}
like image 592
eriel marimon Avatar asked Dec 12 '17 17:12

eriel marimon


1 Answers

In Gradle you only have a parent->child relationship in a multi-module project. You do not have a child->parent definition as you have in Maven.

So you usually have a parent folder where you have a settings.gradle that contains the references to its children.

Like so (parent settings.gradle):

include 'sub-module-1'
include 'sub-module-2

Then you have two sub-folder sub-module-1 and sub-module-2 which contains their own build.gradle files.

But, coming back to your case, you don't need to have any of that when you are just using the spring-boot plugin org.springframework.boot plugin will configure all the necessary dependencies so you only need to add the optional dependencies you want.

like image 111
John Avatar answered Oct 21 '22 17:10

John