Skip to content

Commit

Permalink
Moves the Maven publish Gradle configuration into a Gradle convention…
Browse files Browse the repository at this point in the history
… plugin. This splits the build logic for publication and allows different projects to determine whether they publish to Maven rather than having to track this with conditionals in the root Gradle project. (opensearch-project#4421)

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable authored Apr 16, 2024
1 parent a20756c commit a5bdcf2
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 53 deletions.
55 changes: 4 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ allprojects {
apply plugin: 'checkstyle'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'com.github.jk1.dependency-license-report'
apply plugin: 'maven-publish'

group = 'org.opensearch.dataprepper'

ext {
mavenPublicationRootFile = file("${rootProject.buildDir}/m2")
Expand All @@ -42,53 +39,10 @@ allprojects {
}
}

if(project.name.startsWith('data-prepper') || project.parent != null && project.parent.name.equals('data-prepper-plugins')) {
project.plugins.withType(JavaPlugin).configureEach {
java {
withJavadocJar()
withSourcesJar()
}

afterEvaluate {
project.publishing {
repositories {
maven {
url "file://${mavenPublicationRootFile.absolutePath}"
}
}
publications {
mavenJava(MavenPublication) {
from project.components.findByName("java") ?: project.components.findByName("javaLibrary")

groupId = project.group
artifactId = project.name
version = project.version

pom {
name = project.name
description = "Data Prepper project: ${project.name}"
url = 'https://github.com/opensearch-project/data-prepper'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
name = 'OpenSearch'
url = 'https://github.com/opensearch-project'
}
}
scm {
url = 'https://github.com/opensearch-project/data-prepper'
}
}
}
}
}
}
project.plugins.withType(JavaPlugin).configureEach {
java {
withJavadocJar()
withSourcesJar()
}
}

Expand All @@ -99,7 +53,6 @@ allprojects {

subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'

java {
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
plugins {
id 'java-gradle-plugin'
id 'java'
id 'groovy-gradle-plugin'
}
52 changes: 52 additions & 0 deletions buildSrc/src/main/groovy/data-prepper.publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'maven-publish'
}

group = 'org.opensearch.dataprepper'

afterEvaluate {
project.publishing {
repositories {
maven {
url "file://${mavenPublicationRootFile.absolutePath}"
}
}
publications {
mavenJava(MavenPublication) {
from project.components.findByName('java') ?: project.components.findByName('javaLibrary')

groupId = project.group
artifactId = project.name
version = project.version

pom {
name = project.name
description = "Data Prepper project: ${project.name}"
url = 'https://github.com/opensearch-project/data-prepper'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
name = 'OpenSearch'
url = 'https://github.com/opensearch-project'
}
}
scm {
url = 'https://github.com/opensearch-project/data-prepper'
}
}
}
}
}
}

4 changes: 4 additions & 0 deletions data-prepper-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

dependencies {
implementation 'io.micrometer:micrometer-core'
implementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

sourceSets {
main {
resources {
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-event/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

group = 'org.opensearch.dataprepper.core'

dependencies {
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

sourceSets {
main {
resources {
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-pipeline-parser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

group = 'org.opensearch.dataprepper.core'

dependencies {
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-plugin-framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

group = 'org.opensearch.dataprepper.core'

dependencies {
Expand Down
5 changes: 3 additions & 2 deletions data-prepper-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ plugins {
id 'java-library'
}

allprojects {
subprojects {
apply plugin: 'data-prepper.publish'
group = 'org.opensearch.dataprepper.plugins'
}

dependencies {
subprojects.forEach { api project(':data-prepper-plugins:' + it.name) }
}
}
1 change: 1 addition & 0 deletions data-prepper-test-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

plugins {
id 'java'
id 'data-prepper.publish'
}

group = 'org.opensearch.dataprepper.test'
Expand Down
4 changes: 4 additions & 0 deletions data-prepper-test-event/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

plugins {
id 'data-prepper.publish'
}

group = 'org.opensearch.dataprepper.test'

dependencies {
Expand Down

0 comments on commit a5bdcf2

Please sign in to comment.