Skip to content

Commit

Permalink
Build logic changes (#41)
Browse files Browse the repository at this point in the history
* Migrate some build logic to conventions of other repos.

* spotlessApply

* Fix groovy compile version

* Regex
  • Loading branch information
Anuraag Agrawal authored Jun 30, 2021
1 parent 26476ae commit 4bfd97d
Show file tree
Hide file tree
Showing 45 changed files with 285 additions and 533 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,10 @@ jobs:
distribution: adopt
java-version: 11
- uses: burrunan/gradle-cache-action@v1
name: ./gradlew lint
name: Build
with:
arguments: --stacktrace lint
gradle-version: wrapper
job-id: java-contrib
arguments: --stacktrace build
remote-build-cache-proxy-enabled: false
- name: ./gradlew assemble
run: ./gradlew --stacktrace assemble
- name: ./gradlew build
run: ./gradlew --stacktrace --max-workers 2 build
timeout-minutes: 5
- uses: actions/upload-artifact@v2
name: Save unit test results
if: always()
Expand All @@ -53,13 +46,9 @@ jobs:
distribution: adopt
java-version: 11
- uses: burrunan/gradle-cache-action@v1
name: ./gradlew integrationTest
id: integration-test
timeout-minutes: 10
name: Integration Tests
with:
arguments: --stacktrace --max-workers 2 integrationTest
gradle-version: wrapper
job-id: java-contrib
arguments: --stacktrace integrationTest
remote-build-cache-proxy-enabled: false
- uses: actions/upload-artifact@v2
name: Save integrationTest results
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ feature or via instrumentation, this project is hopefully for you.

```bash
# Apply formatting
$ ./gradlew format
$ ./gradlew spotlessApply

# Build the complete project
$ ./gradlew build
Expand Down
36 changes: 2 additions & 34 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
plugins {
id 'com.diffplug.spotless' version '5.1.1'
id "com.github.johnrengelman.shadow" version "6.0.0" apply false
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
id 'com.diffplug.spotless'
id "io.github.gradle-nexus.publish-plugin"
}

description = 'OpenTelemetry Contrib libraries and utilities for the JVM'

allprojects {
group = 'io.opentelemetry.contrib'
version = '1.0.0-alpha'

apply from: "$rootDir/gradle/spotless.gradle"
apply from: "$rootDir/gradle/dependencies.gradle"

it.ext.contrib = "$rootDir/gradle/contrib.gradle"
it.ext.publish = "$rootDir/gradle/publish.gradle"

repositories {
mavenLocal()
jcenter()
mavenCentral()
}
}

task lint(dependsOn: [allprojects.spotlessCheck])
task format(dependsOn: [allprojects.spotlessApply])

task integrationTest {
doFirst {
allprojects.test.each { test ->
test.configure {
systemProperty 'ojc.integration.tests', 'true'
}
}
}
}
integrationTest.finalizedBy allprojects.test

// At this time authentication relies on sonatypeUsername and sonatypePassword project properties or
// ORG_GRADLE_PROJECT_sonatypeUsername and ORG_GRADLE_PROJECT_sonatypePassword environment variables.
nexusPublishing {
Expand Down
16 changes: 16 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
`kotlin-dsl`
// When updating, update below in dependencies too
id("com.diffplug.spotless") version "5.14.0"
}

repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}

dependencies {
// When updating, update above in plugins too
implementation("com.diffplug.spotless:spotless-plugin-gradle:5.14.0")
}
37 changes: 37 additions & 0 deletions buildSrc/src/main/kotlin/otel.groovy-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
groovy

id("otel.java-conventions")
id("otel.spotless-conventions")
}

dependencies {
testImplementation("org.spockframework:spock-core:1.3-groovy-2.5") {
exclude("org.codehaus.groovy", "groovy-all")
}
}

spotless {
groovy {
greclipse()
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
excludeJava()
licenseHeaderFile(rootProject.file("config/license/spotless.license.java"), "(package|import|class|def|// Includes work from:)")
}

groovyGradle {
greclipse()
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}

tasks {
withType<GroovyCompile> {
sourceCompatibility = "8"
targetCompatibility = "8"
}
}
54 changes: 54 additions & 0 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
`java-library`

id("otel.spotless-conventions")
}

group = "io.opentelemetry.contrib"
version = "1.0.0-alpha"

base.archivesBaseName = "${rootProject.name}-${project.name}"

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}

withJavadocJar()
withSourcesJar()
}

tasks {
withType<JavaCompile>().configureEach {
with(options) {
release.set(8)
}
}

val integrationTest by registering {
dependsOn(test)
}

test {
if (gradle.startParameter.taskNames.contains(integrationTest.name)) {
systemProperty("ojc.integration.tests", "true")
}
}
}

val dependencyManagement by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
isVisible = false
}

dependencies {
dependencyManagement(platform(project(":dependencyManagement")))
afterEvaluate {
configurations.configureEach {
if (isCanBeResolved && !isCanBeConsumed) {
extendsFrom(dependencyManagement)
}
}
}
}
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("com.diffplug.spotless")
}

spotless {
java {
googleJavaFormat()
licenseHeaderFile(rootProject.file("config/license/spotless.license.java"), "(package|import|public|class|// Includes work from:)")
}

format("misc") {
// not using "**/..." to help keep spotless fast
target(".gitignore", "*.md", "src/**/*.md", "*.sh", "src/**/*.properties")
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
4 changes: 4 additions & 0 deletions config/license/spotless.license.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
67 changes: 67 additions & 0 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

plugins {
`java-platform`

id("com.github.ben-manes.versions")
}

data class DependencySet(val group: String, val version: String, val modules: List<String>)

val dependencyVersions = hashMapOf<String, String>()
rootProject.extra["versions"] = dependencyVersions

val DEPENDENCY_BOMS = listOf(
"io.opentelemetry:opentelemetry-bom:1.0.0",
"io.opentelemetry:opentelemetry-bom-alpha:1.0.0-alpha"
)

val DEPENDENCY_SETS = listOf<DependencySet>()

val DEPENDENCIES = listOf(
"org.spockframework:spock-core:1.3-groovy-2.5"
)

javaPlatform {
allowDependencies()
}

dependencies {
for (bom in DEPENDENCY_BOMS) {
api(enforcedPlatform(bom))
val split = bom.split(':')
dependencyVersions[split[0]] = split[2]
}
constraints {
for (set in DEPENDENCY_SETS) {
for (module in set.modules) {
api("${set.group}:${module}:${set.version}")
dependencyVersions[set.group] = set.version
}
}
for (dependency in DEPENDENCIES) {
api(dependency)
val split = dependency.split(':')
dependencyVersions[split[0]] = split[2]
}
}
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isGuava = version.endsWith("-jre")
val isStable = stableKeyword || regex.matches(version) || isGuava
return isStable.not()
}

tasks {
named<DependencyUpdatesTask>("dependencyUpdates") {
revision = "release"
checkConstraints = true

rejectVersionIf {
isNonStable(candidate.version)
}
}
}
4 changes: 3 additions & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply from: project.contrib
plugins {
id("otel.java-conventions")
}

ext.libraryName = 'OpenTelemetry Java Contrib Example'
description = 'An example OpenTelemetry Java Contrib library'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.example;

public class Library {
Expand Down
22 changes: 0 additions & 22 deletions gradle/contrib.gradle

This file was deleted.

27 changes: 0 additions & 27 deletions gradle/dependencies.gradle

This file was deleted.

16 changes: 0 additions & 16 deletions gradle/java.license.header

This file was deleted.

Loading

0 comments on commit 4bfd97d

Please sign in to comment.