How to create a Maven parent POM equivalent in gradle?

I have a Common parent in maven having just as a pom packaging which uses a common dependency creates by me.
Now I need the Common parent in Gradle.
Is it possible to have a similar structure using gradle ?

When you have a Gradle multiproject build structure, the top-level build.gradle is where you would put things like this. Read the “Multi-project Builds” chapter in the user guide.

1 Like

I tried to use gradle init command for the below pom, but it is throwing error that could not convert maven pom to gradle build. I am not able to identify the issue.

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

<groupId>com.core.lab</groupId>
<artifactId>CommonTestApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>CommonTestApp</name>
<description>Demo project for Coreload-Parent</description>

<parent>
	<groupId>com.java</groupId>
	<artifactId>core-parent</artifactId>
	<version>1-SNAPSHOT</version>
</parent>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>1.8</java.version>
	<spring-cloud.version>Dalston.SR1</spring-cloud.version>
</properties>

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>${spring-cloud.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

<dependencies>
	<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix -->
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-hystrix</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-config</artifactId>
	</dependency>
</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>

Your objective can likely be solved via a subprojects closure in the root project

Eg:

subprojects {
    apply plugin: 'java' 
    dependencies {
        compile 'foo:bar:1.0'
    } 
} 

Once your project inevitably grows and you want to deal with a subset of projects you can

[':project1', ':project2'].each {
    project(it) {
        dependencies {
            compile 'foo:bar:1.0'
        } 
    } 
} 

OR

subprojects.find { it.name.startsWith('foo') }.each { project -> 
    project.dependencies {
        compile 'foo:bar:1.0'
    } 
} 
1 Like

Thank you very much.

Sorry, but I think, that question is little different. We have many modular application and many a many modules (let say 10 OSGi application and 200 bundles). I dont think so, that multiproject build is suitable. Let say 80% of bundles (1 bundle = 1 project) are shared in many application.

Could I have 1 “subproject” in many “top project”? How?

I’m not sure I understand the question, can you give a bit more info?