Skip to content

Commit 7a85089

Browse files
refs #227 refs #228: Includes pom.xml in Jars, fixes gradle consumer (#229)
Add manual configuration for including the pom.xml and pom.properties file in the Jar META-INF folder. Gradle projects were failing to use the library unless they explicitly defined the AWS BOM. This was not the case with Maven users. The cause was the BOM being an `implementation` and not an `api` dependency.
1 parent 906ab97 commit 7a85089

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ subprojects {
3131
dependencies {
3232
// AWS
3333
implementation(platform("software.amazon.awssdk:bom:2.13.58"))
34+
api(platform("software.amazon.awssdk:bom:2.13.58"))
3435

3536
// Spring Boot
36-
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE"))
37+
api(platform("org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE"))
3738

3839
// Lombok
3940
compileOnly("org.projectlombok:lombok:1.18.12")

buildSrc/src/main/kotlin/com/jashmore/gradle/ReleasePlugin.kt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import org.gradle.api.plugins.JavaPluginExtension
1010
import org.gradle.api.publish.PublishingExtension
1111
import org.gradle.api.publish.maven.MavenPublication
1212
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
13+
import org.gradle.api.tasks.bundling.Jar
1314
import org.gradle.kotlin.dsl.configure
1415
import org.gradle.kotlin.dsl.create
1516
import org.gradle.kotlin.dsl.get
17+
import org.gradle.kotlin.dsl.withType
1618
import org.gradle.plugins.signing.SigningExtension
1719
import org.gradle.plugins.signing.SigningPlugin
1820
import java.io.File
1921
import java.net.URI
22+
import java.text.DateFormat
23+
import java.text.SimpleDateFormat
24+
import java.time.OffsetDateTime
25+
import java.time.format.DateTimeFormatter
2026

2127
open class ReleasePluginExtension {
2228
/**
@@ -68,6 +74,9 @@ open class ReleasePlugin : Plugin<Project> {
6874
val deploymentTag = if (isSnapshotVersion(projectVersion)) "HEAD" else "v$projectVersion"
6975

7076
project.subprojects.forEach { subProject ->
77+
val groupId = subProject.group as String
78+
val artifactId = subProject.name.replace(":", "")
79+
7180
val isExamplesModule = subProject.projectDir.path.contains("examples")
7281
val moduleCompilesJava = subProject.plugins.hasPlugin("java")
7382
if (!isExamplesModule && moduleCompilesJava) {
@@ -82,9 +91,9 @@ open class ReleasePlugin : Plugin<Project> {
8291

8392
subProject.configure<PublishingExtension> {
8493
publications {
85-
create<MavenPublication>("mavenJava") {
86-
groupId = subProject.group as String
87-
artifactId = subProject.name.replace(":", "")
94+
create<MavenPublication>("mavenJava") {
95+
this.groupId = groupId
96+
this.artifactId = artifactId
8897
version = projectVersion
8998

9099
from(subProject.components["java"])
@@ -142,6 +151,29 @@ open class ReleasePlugin : Plugin<Project> {
142151
}
143152
}
144153

154+
// Populate the Jars with a pom.xml and pom.properties file
155+
subProject.tasks.withType<Jar> {
156+
into("META-INF/maven/$groupId/$artifactId") {
157+
from(subProject.tasks.getByName("generatePomFileForMavenJavaPublication"))
158+
159+
rename("pom-default.xml", "pom.xml")
160+
}
161+
162+
into("META-INF/maven/$groupId/$artifactId") {
163+
val propertiesFile = File.createTempFile("pom", ".properties")
164+
propertiesFile.writeText("""
165+
# Generated by Gradle
166+
# ${DateTimeFormatter.ISO_DATE_TIME.format(OffsetDateTime.now())}
167+
groupId=${groupId}
168+
artifactId=${artifactId}
169+
version=${projectVersion}
170+
""".trimIndent())
171+
from(propertiesFile)
172+
173+
rename(propertiesFile.name, "pom.properties")
174+
}
175+
}
176+
145177
subProject.configure<SigningExtension> {
146178
// We only want to sign if we are actually publishing to Maven Central
147179
setRequired({ project.gradle.taskGraph.hasTask("publishMavenJavaPublicationToMavenRepository") })

0 commit comments

Comments
 (0)