Skip to content

Commit

Permalink
Add release task to publish all jars. (#4238)
Browse files Browse the repository at this point in the history
This commit adds a task called release which will publish all of the
data prepper jars individually.

Signed-off-by: Adi Suresh <[email protected]>
  • Loading branch information
asuresh8 authored Mar 7, 2024
1 parent 2c018b8 commit 2a20655
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 46 deletions.
11 changes: 6 additions & 5 deletions build-resources.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
ext.coreProjects = [
project(':data-prepper-api'),
project(':data-prepper-core'),
project('data-prepper-plugins:common'),
project('data-prepper-expression'),
project(':data-prepper-logstash-configuration')
]
ext.mavenArtifactProjects = [project(':data-prepper-api')]
project(':data-prepper-expression'),
project(':data-prepper-logstash-configuration'),
project(':data-prepper-main'),
project(':data-prepper-plugins'),
project(':data-prepper-test-common')
]
124 changes: 83 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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'

Expand All @@ -41,6 +42,52 @@ allprojects {
}
}

project.plugins.withType(JavaPlugin).configureEach {
java {
withJavadocJar()
withSourcesJar()
}

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'
}
}
}
}
}
}

checkstyle {
toolVersion = '10.12.3'
}
Expand Down Expand Up @@ -248,47 +295,6 @@ configure(subprojects.findAll {it.name != 'data-prepper-api'}) {
}
}

configure(mavenArtifactProjects) {
java {
withJavadocJar()
withSourcesJar()
}

publishing {
repositories {
maven {
url "file://${mavenPublicationRootFile.absolutePath}"
}
}
publications {
maven(MavenPublication) {
from components.java
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'
}
}
}
}
}
}

configure(coreProjects) {
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
Expand Down Expand Up @@ -332,4 +338,40 @@ task generateThirdPartyReport(type: Copy) {
include 'THIRD-PARTY-NOTICES.txt'
rename 'THIRD-PARTY-NOTICES.txt', 'THIRD-PARTY'
generateThirdPartyReport.dependsOn(generateLicenseReport)
}

// Utility method to recursively collect tasks from all projects and subprojects
def collectTasksRecursively(Project project, String taskName) {
def tasks = []
if (project.plugins.hasPlugin('java') || project.plugins.hasPlugin('java-library')) {
Task task = project.tasks.findByName(taskName)
if (task != null) {
tasks.add(task)
}
}
project.subprojects.each { subproject ->
tasks += collectTasksRecursively(subproject, taskName)
}
return tasks
}

// Define a release task that depends on 'assemble' and 'publish' tasks of all nested projects within the coreProjects
task release {
doLast {
println "Release task completed."
}
}

// Iterate over each core project and collect 'assemble' and 'publish' tasks recursively from them and their nested subprojects
coreProjects.each { coreProject ->
// Ensure that the core project and its subprojects are evaluated
evaluationDependsOn(coreProject.path)

// Recursively collect 'assemble' and 'publishToMavenLocal' tasks for the core project
def assembleTasks = collectTasksRecursively(coreProject, 'assemble')
def publishTasks = collectTasksRecursively(coreProject, 'publish')

// Add these tasks as dependencies of the release task
release.dependsOn assembleTasks
release.dependsOn publishTasks
}
4 changes: 4 additions & 0 deletions data-prepper-expression/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ jacocoTestCoverageVerification {
}))
}
}

tasks.named('sourcesJar').configure {
dependsOn 'generateGrammarSource'
}
5 changes: 5 additions & 0 deletions data-prepper-logstash-configuration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ jacocoTestCoverageVerification {
}))
}
}

tasks.named('sourcesJar').configure {
dependsOn 'generateGrammarSource'
}

0 comments on commit 2a20655

Please sign in to comment.