Skip to content

Commit

Permalink
Merge pull request #243 from Goooler/master
Browse files Browse the repository at this point in the history
Migrate buildSrc to composite build
  • Loading branch information
melix committed Jul 31, 2023
2 parents 3f16ffa + 4cfc127 commit 698923b
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 156 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts → build-logic/build.gradle.kts
Expand Up @@ -23,5 +23,5 @@ repositories {
}

dependencies {
implementation("com.gradle.publish:plugin-publish-plugin:1.1.0")
implementation("com.gradle.publish:plugin-publish-plugin:1.2.0")
}
@@ -0,0 +1,85 @@
/*
* Copyright 2014-2021 the original author or 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.
*/

import org.gradle.api.internal.artifacts.dsl.dependencies.DependencyFactoryInternal
import org.gradle.internal.component.local.model.OpaqueComponentIdentifier

plugins {
groovy
`java-gradle-plugin`
}

val functionalTestSourceSet = sourceSets.create("functionalTest") {
groovy.srcDir("src/funcTest/groovy")
resources.srcDir("src/funcTest/resources")
}

configurations {
getByName("functionalTestImplementation").extendsFrom(testImplementation.get())
getByName("functionalTestRuntimeOnly").extendsFrom(testRuntimeOnly.get())
val pluginsUnderTest by creating {
isCanBeConsumed = false
isCanBeResolved = false
}
val pluginClasspath by creating {
isCanBeConsumed = false
isCanBeResolved = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named<Category>(Category.LIBRARY))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named<Bundling>(Bundling.EXTERNAL))
}
extendsFrom(implementation.get(), runtimeOnly.get(), pluginsUnderTest)
}
testImplementation.get().extendsFrom(pluginsUnderTest)
}

gradlePlugin {
testSourceSets(functionalTestSourceSet)
}

val classpathWithoutDevelopmentLibs: ArtifactView = configurations["pluginClasspath"].incoming.artifactView {
componentFilter { componentId ->
if (componentId is OpaqueComponentIdentifier) {
val classPathNotation = componentId.classPathNotation
return@componentFilter classPathNotation != DependencyFactoryInternal.ClassPathNotation.GRADLE_API &&
classPathNotation != DependencyFactoryInternal.ClassPathNotation.LOCAL_GROOVY
}
true
}
}

tasks.pluginUnderTestMetadata {
pluginClasspath.from(classpathWithoutDevelopmentLibs.files.elements)
}

val functionalTest by tasks.registering(Test::class) {
description = "Runs the functional tests."
group = "verification"
testClassesDirs = functionalTestSourceSet.output.classesDirs
classpath = functionalTestSourceSet.runtimeClasspath
mustRunAfter(tasks.test)

reports {
html.outputLocation = project.file("${html.outputLocation.asFile.get().path}/functional")
junitXml.outputLocation = project.file("${html.outputLocation.asFile.get().path}/functional")
}
}

tasks.check {
dependsOn(functionalTest)
}
29 changes: 18 additions & 11 deletions gradle/test.gradle → ...in/me.champeau.convention-test.gradle.kts
Expand Up @@ -14,22 +14,29 @@
* limitations under the License.
*/

project.tasks.withType(Test).configureEach {
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
tasks.withType<Test>().configureEach {
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) = Unit

onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent != null) {
println("Test results ${project.name}: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)")
}
}

override fun beforeTest(testDescriptor: TestDescriptor) {
logger.lifecycle("Running test: $testDescriptor")
}

override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) = Unit
})

addTestOutputListener { testDescriptor, outputEvent ->
logger.lifecycle("Test: $testDescriptor produced standard out/err: ${outputEvent.message}")
}

testLogging {
showStandardStreams = true
afterSuite { desc, result ->
if (!desc.parent) {
println "Test results ${project.name}: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
}
}
}

useJUnitPlatform()
Expand Down
Expand Up @@ -63,32 +63,32 @@ publishing {
create<MavenPublication>("mavenJava") {
from(components["java"])
pom {
name.set("Gradle Plugin for JMH")
description.set(properties.getting("project_description"))
url.set(properties.getting("project_website"))
name = "Gradle Plugin for JMH"
description = properties.getting("project_description")
url = properties.getting("project_website")
issueManagement {
system.set("GitHub")
url.set(properties.getting("project_issues"))
system = "GitHub"
url = properties.getting("project_issues")
}
scm {
url.set(properties.getting("project_website"))
connection.set(properties.getting("project_vcs").map { "scm:git:$it" })
developerConnection.set("scm:git:git@github.com:melix/jmh-gradle-plugin.git")
url = properties.getting("project_website")
connection = properties.getting("project_vcs").map { "scm:git:$it" }
developerConnection = "scm:git:git@github.com:melix/jmh-gradle-plugin.git"
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
name = "The Apache Software License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "repo"
}
}
developers {
developer {
id.set("melix")
name.set("Cédric Champeau")
id = "melix"
name = "Cédric Champeau"
organization {
name.set("Personal")
url.set("https://melix.github.io/blog")
name = "Personal"
url = "https://melix.github.io/blog"
}
}
}
Expand All @@ -113,15 +113,15 @@ tasks.withType<Sign>().configureEach {
}

gradlePlugin {
website.set(properties.get("project_website").toString())
vcsUrl.set(properties.get("project_vcs").toString())
website = properties.get("project_website").toString()
vcsUrl = properties.get("project_vcs").toString()

plugins.create("jmh") {
id = "me.champeau.jmh"
implementationClass = "me.champeau.jmh.JMHPlugin"
displayName = properties.get("project_description").toString()
description = properties.get("project_description").toString()
tags.set(listOf("jmh"))
tags = listOf("jmh")
}
}

Expand Down
12 changes: 5 additions & 7 deletions build.gradle.kts
Expand Up @@ -15,23 +15,21 @@
*/

plugins {
jacoco
id("me.champeau.buildscan-recipes") version "0.2.3"
id("org.nosphere.apache.rat") version "0.8.0"
id("net.nemerosa.versioning") version "3.0.0"
id("com.github.kt3k.coveralls") version "2.12.2"
id("me.champeau.convention-test")
id("me.champeau.convention-funcTest")
id("me.champeau.plugin-configuration")
id("jacoco")
id("groovy")
}

buildScanRecipes {
recipes("git-status", "travis-ci")
recipe(mapOf("baseUrl" to "https://github.com/melix/jmh-gradle-plugin/tree"), "git-commit")
}

apply(from = "gradle/test.gradle")
apply(from = "gradle/funcTest.gradle")

val jmhVersion: String by project
val spockVersion: String by project
val shadowVersion: String by project
Expand All @@ -43,15 +41,15 @@ dependencies {
testImplementation("org.spockframework:spock-core:$spockVersion") {
exclude(mapOf("group" to "org.codehaus.groovy"))
}
"pluginsUnderTest"("gradle.plugin.com.github.johnrengelman:shadow:$shadowVersion")
pluginsUnderTest("gradle.plugin.com.github.johnrengelman:shadow:$shadowVersion")

testImplementation("org.openjdk.jmh:jmh-core:$jmhVersion")
testImplementation("org.openjdk.jmh:jmh-generator-bytecode:$jmhVersion")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion = JavaLanguageVersion.of(8)
}
withSourcesJar()
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -6,7 +6,7 @@ project_website=https://github.com/melix/jmh-gradle-plugin
project_issues=https://github.com/melix/jmh-gradle-plugin/issues
project_vcs=https://github.com/melix/jmh-gradle-plugin.git

jacocoVersion = 0.8.8
jacocoVersion = 0.8.10
jmhVersion = 1.36
shadowVersion = 7.1.2
spockVersion = 2.3-groovy-3.0
Expand Down
81 changes: 0 additions & 81 deletions gradle/funcTest.gradle

This file was deleted.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down

0 comments on commit 698923b

Please sign in to comment.