-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generateBuildSubstitutions task to bom projects. #3653
Merged
jkwatson
merged 7 commits into
open-telemetry:main
from
dynatrace-oss-contrib:compositebuild-snippet
Sep 26, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
346f237
Add generateBuildSubstitutions task to bom projects.
Oberon00 5982e3f
Fix typo in filter.
Oberon00 74fc416
Add convenience task to root project.
Oberon00 bb7b3f8
Add documentation for how to use composite builds.
Oberon00 dc55f89
Add one more link to gradle docs.
Oberon00 04d9b4a
Wrong variable name.
Oberon00 e932ae1
Update CONTRIBUTING.md
Oberon00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
plugins { | ||
id("java-platform") | ||
id("otel.publish-conventions") | ||
id("otel.bom-conventions") | ||
} | ||
|
||
description = "OpenTelemetry Bill of Materials (Alpha)" | ||
group = "io.opentelemetry" | ||
base.archivesBaseName = "opentelemetry-bom-alpha" | ||
|
||
rootProject.subprojects.forEach { subproject -> | ||
if (!project.name.startsWith("bom")) { | ||
evaluationDependsOn(subproject.path) | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
dependencies { | ||
constraints { | ||
rootProject.subprojects | ||
.sortedBy { it.findProperty("archivesBaseName") as String? } | ||
.filter { !it.name.startsWith("bom") } | ||
.filter { it.findProperty("otel.release") == "alpha" } | ||
.forEach { project -> | ||
project.plugins.withId("maven-publish") { | ||
api(project) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
otelBom.projectFilter.set { it.findProperty("otel.release") == "alpha" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
plugins { | ||
id("java-platform") | ||
id("otel.publish-conventions") | ||
id("otel.bom-conventions") | ||
} | ||
|
||
description = "OpenTelemetry Bill of Materials" | ||
group = "io.opentelemetry" | ||
base.archivesBaseName = "opentelemetry-bom" | ||
|
||
rootProject.subprojects.forEach { subproject -> | ||
if (project != subproject) { | ||
evaluationDependsOn(subproject.path) | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
dependencies { | ||
constraints { | ||
rootProject.subprojects | ||
.sortedBy { it.findProperty("archivesBaseName") as String? } | ||
.filter { !it.name.startsWith("bom") } | ||
.filter { !it.hasProperty("otel.release") } | ||
.forEach { project -> | ||
project.plugins.withId("maven-publish") { | ||
api(project) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
otelBom.projectFilter.set { !it.hasProperty("otel.release") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,12 @@ nexusPublishing { | |
} | ||
} | ||
|
||
// The BOM projects register dependent tasks that actually do the generating. | ||
tasks.register("generateBuildSubstitutions") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to copy-paste this. |
||
group = "publishing" | ||
description = "Generate a code snippet that can be copy-pasted for use in composite builds." | ||
} | ||
|
||
subprojects { | ||
group = "io.opentelemetry" | ||
} |
14 changes: 14 additions & 0 deletions
14
buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelBomExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.gradle | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import java.util.function.Predicate | ||
|
||
abstract class OtelBomExtension { | ||
abstract val projectFilter: Property<Predicate<Project>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import io.opentelemetry.gradle.OtelBomExtension | ||
import org.gradle.kotlin.dsl.create | ||
|
||
plugins { | ||
id("otel.publish-conventions") | ||
id("java-platform") | ||
} | ||
|
||
if (!project.name.startsWith("bom")) { | ||
throw IllegalStateException("Name of BOM projects must start with 'bom'.") | ||
} | ||
|
||
rootProject.subprojects.forEach { subproject -> | ||
if (!subproject.name.startsWith("bom")) { | ||
evaluationDependsOn(subproject.path) | ||
} | ||
} | ||
val otelBom = extensions.create<OtelBomExtension>("otelBom") | ||
|
||
val generateBuildSubstitutions by tasks.registering { | ||
group = "publishing" | ||
description = "Generate a code snippet that can be copy-pasted for use in composite builds." | ||
} | ||
|
||
tasks.named("publish") { | ||
dependsOn(generateBuildSubstitutions) | ||
} | ||
|
||
rootProject.tasks.named(generateBuildSubstitutions.name) { | ||
dependsOn(generateBuildSubstitutions) | ||
} | ||
|
||
afterEvaluate { | ||
otelBom.projectFilter.finalizeValue() | ||
val bomProjects = rootProject.subprojects | ||
.sortedBy { it.findProperty("archivesBaseName") as String? } | ||
.filter { !it.name.startsWith("bom") } | ||
.filter(otelBom.projectFilter.get()::test) | ||
.filter { it.plugins.hasPlugin("maven-publish") } | ||
|
||
generateBuildSubstitutions { | ||
val outputFile = File(buildDir, "substitutions.gradle.kts") | ||
outputs.file(outputFile) | ||
val substitutionSnippet = bomProjects.joinToString( | ||
separator = "\n", | ||
prefix = "dependencySubstitution {\n", | ||
postfix = "\n}\n" | ||
) { project -> | ||
val publication = project.publishing.publications.getByName("mavenPublication") as MavenPublication | ||
" substitute(module(\"${publication.groupId}:${publication.artifactId}\")).using(project(\"${project.path}\"))" | ||
} | ||
inputs.property("projectPathsAndArtifactCoordinates", substitutionSnippet) | ||
doFirst { | ||
outputFile.writeText(substitutionSnippet) | ||
} | ||
} | ||
bomProjects.forEach { project -> | ||
dependencies { | ||
constraints { | ||
api(project) | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still cumbersome. If anyone knows a better format I could generate that could be used in a more straight-forward way, that would be appreciated.