diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..37d06131 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +indent_style = space + +[{*.sh,gradlew}] +end_of_line = lf + +[{*.bat,*.cmd}] +end_of_line = crlf + +[{*.kts,*.kt}] +max_line_length = 100 +# Google Kotlin code style uses 2 spaces for indentation +# See https://github.com/GoogleCloudPlatform/app-gradle-plugin/pull/398/files#r984944216 +indent_size = 2 diff --git a/build.gradle.kts b/build.gradle.kts index fe3c3e8c..f3855c9d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,3 @@ -import net.researchgate.release.GitAdapter.GitConfig -import java.util.Date -import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL - /* * Copyright 2022 Google LLC. All Rights Reserved. * @@ -18,10 +14,13 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL * limitations under the License. * */ +import net.researchgate.release.GitAdapter.GitConfig +import java.util.Date +import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL plugins { id("java") - id("maven") + id("maven-publish") id("java-gradle-plugin") id("net.researchgate.release") version "2.6.0" id("com.github.sherter.google-java-format") version "0.9" @@ -36,13 +35,16 @@ repositories { java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 + withSourcesJar() + withJavadocJar() } group = "com.google.cloud.tools" dependencies { - implementation(localGroovy()) - implementation(gradleApi()) + // Gradle will definitely supply the proper API at the runtime, so we should not + // ask for anything else. + compileOnly(gradleApi()) api("com.google.cloud.tools:appengine-plugins-core:0.9.9") testImplementation("commons-io:commons-io:2.11.0") @@ -56,7 +58,7 @@ tasks.wrapper { gradleVersion = "6.9" } -tasks.jar.configure { +tasks.jar { manifest { attributes( mapOf( @@ -71,91 +73,177 @@ tasks.jar.configure { } } -tasks.withType().configureEach { - options.compilerArgs = options.compilerArgs + listOf( - "-Xlint:all" - ) +tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:all") } -/* TESTING */ -tasks.test.configure { +// +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 Source Context Gradle Plugin" + description = + "This Gradle plugin injects source code context for cloud debugging." + } + } +} +// + +// +tasks.test { testLogging { showStandardStreams = true exceptionFormat = FULL } } -sourceSets { - create("integTest") { - compileClasspath += main.get().output - runtimeClasspath += main.get().output - } +val integTestSourceSet = sourceSets.create("integTest") { + compileClasspath += sourceSets.main.get().output + runtimeClasspath += sourceSets.main.get().output } configurations { - named("integTestCompile").get().extendsFrom(testCompileClasspath.get()) - named("integTestRuntime").get().extendsFrom(testRuntimeClasspath.get()) + "integTestImplementation" { + extendsFrom(testImplementation.get()) + } + "integTestRuntimeOnly" { + extendsFrom(testRuntimeOnly.get()) + } } -tasks.register("integTest") { - testClassesDirs = sourceSets.getByName("integTest").output.classesDirs - classpath = sourceSets.getByName("integTest").runtimeClasspath +val integTest by tasks.registering(Test::class) { + testClassesDirs = integTestSourceSet.output.classesDirs + classpath = integTestSourceSet.runtimeClasspath outputs.upToDateWhen { false } } -/* TESTING */ +// + +// +val generatePom by tasks.registering { + description = + "Generates all the pom files to ${buildDir.name}/publications/ for manual inspection" + group = "release" + dependsOn(tasks.withType()) +} +val tempRepoPath = "$buildDir/repo" -/* RELEASING */ -tasks.register("sourceJar") { - from(sourceSets.main.get().allJava) - archiveClassifier.set("sources") +val cleanTempRepo by tasks.registering(Delete::class) { + delete(tempRepoPath) } -tasks.register("javadocJar") { - dependsOn(tasks.javadoc) - from(tasks.javadoc.map { it.destinationDir!! }) - archiveClassifier.set("javadoc") +tasks.withType().configureEach { + dependsOn(cleanTempRepo) } -project.afterEvaluate { - tasks.register("writePom") { - val outputFile = file("$buildDir/pom/${project.name}-${project.version}.pom") - outputs.file(outputFile) +// ./gradlew publishToTmpMaven would publish the files to build/repo, so they can be signed and released +val publishToTmpMaven by tasks.registering { + description = "Publish Maven publications to $tempRepoPath" + group = PublishingPlugin.PUBLISH_TASK_GROUP + dependsOn("publishAllPublicationsToTmpMavenRepository") +} - doLast { - maven { +publishing { + repositories { + maven { + name = "tmpMaven" + url = uri(tempRepoPath) + } + } + publications { + // java-gradle-plugin adds publication late, so we need afterEvaluate here + afterEvaluate { + // Configure and for the java module of the plugin + named("pluginMaven") { pom { - project { - withGroovyBuilder { - "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") - } - } - } + name.set("App Engine Gradle Plugin") + description.set("This Gradle plugin provides tasks to build and deploy Google App Engine applications.") + } + } + } + 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") + } + } + pom { + // + 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") } - }.writeTo(outputFile) + } + 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") + } + // } } } @@ -163,15 +251,30 @@ project.afterEvaluate { // for kokoro releases -tasks.register("prepareRelease") { - from(tasks.jar) - from(tasks.named("sourceJar")) - from(tasks.named("javadocJar")) - from(tasks.named("writePom")) - - into("${buildDir}/release-artifacts") - - dependsOn(tasks.build) +val prepareRelease by tasks.registering(Sync::class) { + description = "Copy release artifacts to ${buildDir.name}/release-artifacts/" + group = "release" + dependsOn(tasks.publish) + into("$buildDir/release-artifacts") + from(tempRepoPath) { + include("**/appengine-gradle-plugin/**/*.jar") + include("**/appengine-gradle-plugin/**/*.module") + include("**/appengine-gradle-plugin/**/*.pom") + // Flatten hierarchy + eachFile { + path = "plugin-artifacts/$name" + } + } + from(tempRepoPath) { + include("**/*.gradle.plugin/**/*.pom") + // Flatten hierarchy + eachFile { + path = "plugin-markers/$name" + } + } + // Flattening the hierarchy leaves empty directories, + // do not copy those + includeEmptyDirs = false } release { @@ -181,15 +284,15 @@ release { requireBranch = """^release-v\d+.*$""" //regex } } -/* RELEASING */ +// -/* FORMATTING */ +// googleJavaFormat { toolVersion = "1.7" } -tasks.check.configure { +tasks.check { dependsOn(tasks.verifyGoogleJavaFormat) } tasks.withType().configureEach { @@ -202,16 +305,20 @@ tasks.withType().configureEach { checkstyle { toolVersion = "8.37" // Get the google_checks.xml file from the actual tool we're invoking. - config = resources.text.fromArchiveEntry(configurations.checkstyle.get().files.first(), "google_checks.xml") + config = resources.text.fromArchiveEntry( + configurations.checkstyle.map { it.first() }, + "google_checks.xml" + ) maxErrors = 0 maxWarnings = 0 - tasks.checkstyleTest.configure { - enabled = false - } } -/* FORMATTING */ -/* TEST COVERAGE */ +tasks.checkstyleTest { + enabled = false +} +// + +// jacoco { toolVersion = "0.8.8" } @@ -222,4 +329,4 @@ tasks.jacocoTestReport { html.isEnabled = false } } -/* TEST COVERAGE */ +// diff --git a/gradle.properties b/gradle.properties index 39759aff..30afad39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,5 @@ version = 2.4.6-SNAPSHOT + +org.gradle.parallel=true + +kotlin.code.style=official 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