I have a Gradle 7.0 publish task defined in my Java Spring boot project sub module build.gradle file like this:
publishing {
publications {
maven(MavenPublication) {
groupId 'com.sportswin.soa'
artifactId 'soa-auth-api'
version('1.0.0-SNAPSHOT')
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
repositories {
maven {
url = version.endsWith('SNAPSHOT') ? "${dabaiSnapshotRepo}" : "${dabaiReleaseRepo}"
url = "$url"
credentials {
username "$mavenLoginName"
password "$mavenPassword"
}
}
}
}
It works fine in each of my sub module. The only problem is that this code snippet must be copied to each of my sub module. Now the sub module increased more than 50+. I have to copy and paste it in each location.
Is it possible to define the publish task as a public task and I only need to pass some parameters like the groupId, artifactId, version? What should I do to make it work like this so I do not have to copy and paste the duplicate code snippet?
My project structure is like this:
rootProject
-- build.gradle
-- setting.gradle
module1
-- build.gradle
module2
-- build.gradle
BTW, this is the full sub module build.gradle:
project(":soa-auth") {
dependencies {
}
}
project(":soa-auth:soa-auth-api") {
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
api project(":soa-misc-biz")
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.sportswin.soa'
artifactId 'soa-auth-api'
version('1.0.0-SNAPSHOT')
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
repositories {
maven {
url = "${dabaiSnapshotRepo}"
url = "$url"
credentials {
username "$mavenLoginName"
password "$mavenPassword"
}
}
}
}
}
project(":soa-auth:soa-auth-service") {
archivesBaseName = "soa-auth-service"
version = "1.0.0-SNAPSHOT"
bootJar {
manifest {
attributes 'Start-Class': 'com.sportswin.soa.auth.AppStarter'
}
}
dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
implementation project(":soa-auth:soa-auth-api")
}
}
I am glad to supply any extra information to solve this problem.