From 4c905c838e618f0a6d1c7e4d4f44048ce12fb593 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Mon, 15 Feb 2021 02:39:51 +0300 Subject: [PATCH] Refactor Maven publication: maven -> maven-publish, Groovy DSL -> Kotlin DSL --- build.gradle | 188 ------------ build.gradle.kts | 284 ++++++++++++++++++ gradle.properties | 5 + settings.gradle => settings.gradle.kts | 0 ...tools.appengine-appenginewebxml.properties | 16 - ...e.cloud.tools.appengine-appyaml.properties | 16 - ....cloud.tools.appengine-flexible.properties | 17 -- ....cloud.tools.appengine-standard.properties | 17 -- ...om.google.cloud.tools.appengine.properties | 17 -- ...ogle.cloud.tools.source-context.properties | 17 -- 10 files changed, 289 insertions(+), 288 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (100%) delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appenginewebxml.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appyaml.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-flexible.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-standard.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine.properties delete mode 100644 src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.source-context.properties diff --git a/build.gradle b/build.gradle deleted file mode 100644 index e2f15453..00000000 --- a/build.gradle +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2017 Google LLC. All Rights Reserved. - * - * 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. - * - */ - -plugins { - id 'java' - id 'maven' - id 'java-gradle-plugin' - id 'net.researchgate.release' version '2.6.0' - id 'com.github.sherter.google-java-format' version '0.8' - id 'checkstyle' - id 'jacoco' -} - -repositories { - mavenCentral() -} - -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - -group = 'com.google.cloud.tools' - -dependencies { - compile localGroovy() - compile gradleApi() - compile 'com.google.cloud.tools:appengine-plugins-core:0.9.1' - - testCompile 'commons-io:commons-io:2.4' - testCompile 'junit:junit:4.12' - testCompile 'org.hamcrest:hamcrest-library:1.3' - testCompile 'org.mockito:mockito-core:2.23.4' -} - -wrapper { - gradleVersion = '4.9' -} - -jar { - manifest { - attributes 'Implementation-Title': project.name, - 'Implementation-Version': version, - 'Built-By': System.getProperty('user.name'), - 'Built-Date': new Date(), - 'Built-JDK': System.getProperty('java.version'), - 'Built-Gradle': gradle.gradleVersion - } -} - -/* TESTING */ -test { - testLogging { - showStandardStreams = true - exceptionFormat = 'full' - } -} - -sourceSets { - integTest { - compileClasspath += main.output - runtimeClasspath += main.output - } -} - -configurations { - integTestCompile.extendsFrom testCompile - integTestRuntime.extendsFrom testRuntime -} - -task integTest(type: Test) { - testClassesDirs = sourceSets.integTest.output.classesDirs - classpath = sourceSets.integTest.runtimeClasspath - outputs.upToDateWhen { false } -} -/* TESTING */ - - -/* RELEASING */ -task sourceJar(type: Jar) { - from sourceSets.main.allJava - classifier 'sources' -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - from javadoc.destinationDir - classifier = 'javadoc' -} - -task writePom { - project.afterEvaluate { - def outputFile = file("$buildDir/pom/${project.name}-${project.version}.pom") - outputs.file outputFile - - doLast { - pom { - project { - name 'App Engine Gradle Plugin' - description 'This Gradle plugin provides tasks to build and deploy Google App Engine applications.' - url 'https://github.com/GoogleCloudPlatform/app-gradle-plugin' - inceptionYear '2016' - - scm { - url 'https://github.com/GoogleCloudPlatform/app-gradle-plugin' - connection 'scm:https://github.com/GoogleCloudPlatform/app-gradle-plugin.git' - developerConnection 'scm:git://github.com/GoogleCloudPlatform/app-gradle-plugin.git' - } - - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - - developers { - developer { - id 'loosebazooka' - name 'Appu Goundan' - email 'appu@google.com' - } - } - } - }.writeTo(outputFile) - } - } -} - -// for kokoro releases -task prepareRelease(type: Copy) { - from jar - from sourceJar - from javadocJar - from writePom - - into "${buildDir}/release-artifacts" - - dependsOn build - dependsOn cleanPrepareRelease -} - -release { - tagTemplate = 'v$version' - git { - requireBranch = /^release_v\d+.*$/ //regex - } -} -/* RELEASING */ - -/* FORMATTING */ -check.dependsOn verifyGoogleJavaFormat -// to auto-format run ./gradlew googleJavaFormat - -checkstyle { - toolVersion = '8.18' - // get the google_checks.xml file from the actual tool we're invoking - config = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml') - maxErrors = 0 - maxWarnings = 0 - checkstyleTest.enabled = false -} -/* FORMATTING */ - -/* TEST COVERAGE */ -jacoco { - toolVersion = '0.8.6' -} - -jacocoTestReport { - reports { - xml.enabled true - html.enabled false - } -} -/* TEST COVERAGE */ diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..8321dc78 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,284 @@ +/* + * Copyright 2017 Google LLC. All Rights Reserved. + * + * 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.tasks.testing.logging.TestExceptionFormat + +plugins { + java + `maven-publish` + `java-gradle-plugin` + id("net.researchgate.release") version "2.6.0" + id("com.github.sherter.google-java-format") version "0.8" + checkstyle + jacoco +} + +repositories { + mavenCentral() +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + withSourcesJar() + withJavadocJar() +} + +group = "com.google.cloud.tools" + +dependencies { + implementation(localGroovy()) + implementation(gradleApi()) + implementation("com.google.cloud.tools:appengine-plugins-core:0.9.1") + + testImplementation("commons-io:commons-io:2.4") + testImplementation("junit:junit:4.12") + testImplementation("org.hamcrest:hamcrest-library:1.3") + testImplementation("org.mockito:mockito-core:2.23.4") +} + +tasks { + wrapper { + gradleVersion = "6.8.2" + } + // See https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html#sub:disabling-gmm-publication + // For now, disable module metadata files since they need extra testing. + // Improper metadata might cause issues when consuming the dependency in Gradle + withType().configureEach { + enabled = false + } + jar { + manifest { + attributes( + "Implementation-Title" to project.name, + "Implementation-Version" to project.version, + "Built-By" to providers.systemProperty("user.name"), + "Built-Date" to `java.time`.Instant.now().toString(), + "Built-JDK" to providers.systemProperty("java.version"), + "Built-Gradle" to gradle.gradleVersion + ) + } + } +} + +/* GRADLE PLUGINS */ +gradlePlugin { + plugins { + create("appengine") { + id = "$group.appengine" + implementationClass = "com.google.cloud.tools.gradle.appengine.AppEnginePlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + create("appengine-appenginewebxml") { + id = "$group.appengine-appenginewebxml" + implementationClass = + "com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + create("appengine-appyaml") { + id = "$group.appengine-appyaml" + implementationClass = + "com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlPlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + create("appengine-flexible") { + id = "$group.appengine-flexible" + implementationClass = + "com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlPlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + create("appengine-standard") { + id = "$group.appengine-standard" + implementationClass = + "com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + create("source-context") { + id = "$group.source-context" + implementationClass = + "com.google.cloud.tools.gradle.appengine.sourcecontext.SourceContextPlugin" + displayName = "App Engine Gradle Plugin" + description = + "This Gradle plugin provides tasks to build and deploy Google App Engine applications." + } + } +} + +/* TESTING */ +tasks.test { + testLogging { + showStandardStreams = true + exceptionFormat = TestExceptionFormat.FULL + } +} + +val integTestSourceSet = sourceSets.create("integTest") { + compileClasspath += sourceSets.main.get().output + runtimeClasspath += sourceSets.main.get().output +} + +configurations { + "integTestImplementation" { + extendsFrom(testImplementation.get()) + } + "integTestRuntime" { + extendsFrom(testRuntime.get()) + } +} + +// +val integTest by tasks.registering(Test::class) { + testClassesDirs = integTestSourceSet.output.classesDirs + classpath = integTestSourceSet.runtimeClasspath + outputs.upToDateWhen { false } +} +// + +// +val generatePom by tasks.registering { + description = "Generates all the pom files to build/publications/ for manual inspection" + group = "release" + dependsOn(tasks.withType()) +} + +publishing { + publications { + withType { + // Use the resolved versions in pom.xml + // Gradle might have different resolution rules, so we set the versions + // that were used in Gradle build/test. + versionMapping { + usage(Usage.JAVA_RUNTIME) { + fromResolutionResult() + } + usage(Usage.JAVA_API) { + fromResolutionOf("runtimeClasspath") + } + } + // Skip name and description for plugin markers + if (name == "pluginMaven") { + pom { + name.set("App Engine Gradle Plugin") + description.set("This Gradle plugin provides tasks to build and deploy Google App Engine applications.") + } + } + pom { + // + withXml { + val sb = asString() + var s = sb.toString() + // compile is Maven default, so delete it + s = s.replace("compile", "") + // Cut because all dependencies have the resolved versions + s = s.replace( + Regex( + ".*?", + RegexOption.DOT_MATCHES_ALL + ), + "" + ) + sb.setLength(0) + sb.append(s) + // Re-format the XML + asNode() + } + // + // + developers { + developer { + id.set("loosebazooka") + name.set("Appu Goundan") + email.set("appu@google.com") + } + } + url.set("https://github.com/GoogleCloudPlatform/app-gradle-plugin") + inceptionYear.set("2016") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + comments.set("A business-friendly OSS license") + distribution.set("repo") + } + } + issueManagement { + system.set("GitHub") + url.set("https://github.com/GoogleCloudPlatform/app-gradle-plugin/issues") + } + scm { + url.set("https://github.com/GoogleCloudPlatform/app-gradle-plugin") + connection.set("scm:https://github.com/GoogleCloudPlatform/app-gradle-plugin.git") + developerConnection.set("scm:git://github.com/GoogleCloudPlatform/app-gradle-plugin.git") + } + // + } + } + } +} + +release { + tagTemplate = "v\$version" + // https://github.com/researchgate/gradle-release/issues/281#issuecomment-524673725 + (getProperty("git") as net.researchgate.release.GitAdapter.GitConfig).apply { + requireBranch = """^release_v\d+.*$""" //regex + } +} +// + +// +tasks.check { + dependsOn("verifyGoogleJavaFormat") +} +// to auto-format run ./gradlew googleJavaFormat + +checkstyle { + toolVersion = "8.18" + // get the google_checks.xml file from the actual tool we're invoking + config = resources.text.fromArchiveEntry( + configurations.checkstyle.map { it.first() }, + "google_checks.xml" + ) + maxErrors = 0 + maxWarnings = 0 +} +tasks.checkstyleTest { + enabled = false +} +// + +// +jacoco { + toolVersion = "0.8.6" +} + +tasks.jacocoTestReport { + reports { + xml.isEnabled = true + html.isEnabled = false + } +} +// diff --git a/gradle.properties b/gradle.properties index d903ea94..4da2aadb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,6 @@ +org.gradle.parallel=true + +kotlin.code.style=official +kotlin.parallel.tasks.in.project=true + version = 2.4.2-SNAPSHOT diff --git a/settings.gradle b/settings.gradle.kts similarity index 100% rename from settings.gradle rename to settings.gradle.kts diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appenginewebxml.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appenginewebxml.properties deleted file mode 100644 index 4722509f..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appenginewebxml.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2019 Google LLC. All Rights Reserved. -# -# 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. -# -implementation-class=com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appyaml.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appyaml.properties deleted file mode 100644 index f5395462..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-appyaml.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2018 Google LLC. All Rights Reserved. -# -# 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. -# -implementation-class=com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlPlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-flexible.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-flexible.properties deleted file mode 100644 index a581aac9..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-flexible.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2017 Google LLC. All Rights Reserved. -# -# 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. -# -# -implementation-class=com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlPlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-standard.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-standard.properties deleted file mode 100644 index 6c9ff0df..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine-standard.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2017 Google LLC. All Rights Reserved. -# -# 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. -# -# -implementation-class=com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine.properties deleted file mode 100644 index bfa6e0e1..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.appengine.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2016 Google LLC. All Rights Reserved. -# -# 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. -# -# -implementation-class=com.google.cloud.tools.gradle.appengine.AppEnginePlugin diff --git a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.source-context.properties b/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.source-context.properties deleted file mode 100644 index f536a008..00000000 --- a/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.source-context.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2016 Google LLC. All Rights Reserved. -# -# 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. -# -# -implementation-class=com.google.cloud.tools.gradle.appengine.sourcecontext.SourceContextPlugin