Skip to content
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

chore: split /build.gradle.kts to build-logic/ plugins #2755

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 5 additions & 19 deletions benchmarks/build.gradle.kts
@@ -1,31 +1,17 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you 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.
* Copyright (c) 2020, PostgreSQL Global Development Group
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 2023 right?

I'm not an expert on these things, but I think you'd need to leave the original notice place and add ours under it to cover subsequent changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point. Ya, we can't remove licenses

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 2023 right?

The copyright date should be "the first date the file was introduced".
In other words, we claim the file is part of pgjdbc since 2020.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave the original notice place and add ours under it to cover subsequent changes.

The original notice was "apache 2" by mistake as it was automatically added, and I did not notice the header was wrong.

* See the LICENSE file in the project root for more information.
*/
plugins {
id("build-logic.java-library")
id("me.champeau.jmh")
}

dependencies {
// Make jmhCompileClasspath resolvable
jmhImplementation(platform(project(":bom")))
jmhImplementation(project(":postgresql"))
// jmhImplementation("com.google.guava:guava")
// jmhImplementation("org.codehaus.janino:commons-compiler")
jmhImplementation("org.openjdk.jmh:jmh-core")
jmhImplementation("org.openjdk.jmh:jmh-generator-annprocess")
jmhImplementation("org.openjdk.jmh:jmh-core:1.12")
jmhImplementation("org.openjdk.jmh:jmh-generator-annprocess:1.12")
}

// See https://github.com/melix/jmh-gradle-plugin
Expand Down
66 changes: 0 additions & 66 deletions bom/build.gradle.kts

This file was deleted.

1 change: 1 addition & 0 deletions build-logic-commons/.gitignore
@@ -0,0 +1 @@
/*/build/
24 changes: 24 additions & 0 deletions build-logic-commons/gradle-plugin/build.gradle.kts
@@ -0,0 +1,24 @@
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion

plugins {
`kotlin-dsl`
}

group = "org.postgresql.build-logic"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files,
// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin
// to make it work.
// See https://github.com/gradle/gradle/issues/17016 regarding expectedKotlinDslPluginsVersion
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
}

kotlinDslPluginOptions {
jvmTarget.set("1.8")
}
@@ -0,0 +1,18 @@
plugins {
id("java-library")
id("org.gradle.kotlin.kotlin-dsl") // this is 'kotlin-dsl' without version
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.validatePlugins {
failOnWarning.set(true)
enableStricterValidation.set(true)
}

kotlinDslPluginOptions {
jvmTarget.set("1.8")
}
9 changes: 9 additions & 0 deletions build-logic-commons/settings.gradle.kts
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
repositories {
gradlePluginPortal()
}
}

rootProject.name = "build-logic-commons"

include("gradle-plugin")
1 change: 1 addition & 0 deletions build-logic/.gitignore
@@ -0,0 +1 @@
/*/build/
27 changes: 27 additions & 0 deletions build-logic/README.md
@@ -0,0 +1,27 @@
# Build logic for pgjdbc

This is a subset of extra plugins for factoring out
the common patterns from the common build logic.

The recommended approach is to use build composition, so every build script
should list all its prerequisites in the top-most `plugins { ... }` block.

The use of `allprojects` and `subprojects` is an anti-pattern as it makes it hard to identify
the configuration for a given project.

Let us consider an example (see `/pgjdbc/build.gradle.kts`):

```kotlin
plugins {
id("build-logic.java-published-library")
id("build-logic.test-junit5")
}

...
```

It means that we deal with a Java library that will be published to Central,
and which uses JUnit 5 for testing.

If you want to see what the logic does, you could open `build-logic.java-published-library.gradle.kts`
and `buildlogic.test-junit5.gradle.kts`.
7 changes: 7 additions & 0 deletions build-logic/basics/build.gradle.kts
@@ -0,0 +1,7 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
implementation(project(":build-parameters"))
}
@@ -0,0 +1,10 @@
plugins {
id("build-logic.build-params")
}

repositories {
if (buildParameters.enableMavenLocal) {
mavenLocal()
}
mavenCentral()
}
@@ -0,0 +1,7 @@
tasks.withType<AbstractArchiveTask>().configureEach {
// Ensure builds are reproducible
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
dirMode = "775".toInt(8)
fileMode = "664".toInt(8)
}
64 changes: 64 additions & 0 deletions build-logic/build-parameters/build.gradle.kts
@@ -0,0 +1,64 @@
plugins {
id("org.gradlex.build-parameters") version "1.4.1"
id("com.github.vlsi.gradle-extensions") version "1.86"
id("build-logic.kotlin-dsl-gradle-plugin")
}

buildParameters {
// Other plugins can contribute parameters, so below list is not exhaustive
enableValidation.set(false)
pluginId("build-logic.build-params")
bool("enableMavenLocal") {
defaultValue.set(true)
description.set("Add mavenLocal() to repositories")
}
bool("coverage") {
defaultValue.set(false)
description.set("Collect test coverage")
}
bool("spotbugs") {
defaultValue.set(false)
description.set("Run SpotBugs verifications")
}
bool("enableCheckerframework") {
defaultValue.set(false)
description.set("Run CheckerFramework (nullness) verifications")
}
bool("enableErrorprone") {
defaultValue.set(false)
description.set("Run ErrorProne verifications")
}
bool("skipCheckstyle") {
defaultValue.set(false)
description.set("Skip Checkstyle verifications")
}
bool("skipAutostyle") {
defaultValue.set(false)
description.set("Skip AutoStyle verifications")
}
bool("skipForbiddenApis") {
defaultValue.set(false)
description.set("Skip forbidden-apis verifications")
}
bool("skipJavadoc") {
defaultValue.set(false)
description.set("Skip javadoc generation")
}
bool("failOnJavadocWarning") {
defaultValue.set(true)
description.set("Fail build on javadoc warnings")
}
bool("enableGradleMetadata") {
defaultValue.set(false)
description.set("Generate and publish Gradle Module Metadata")
}
// Note: it does not work in tr_TR locale due to https://github.com/gradlex-org/build-parameters/issues/87
string("includeTestTags") {
defaultValue.set("")
description.set("Lists tags to include in test execution. For instance -PincludeTestTags=!org.postgresql.test.SlowTests, or or -PincludeTestTags=!org.postgresql.test.Replication")
}
bool("useGpgCmd") {
defaultValue.set(false)
description.set("By default use Java implementation to sign artifacts. When useGpgCmd=true, then gpg command line tool is used for signing artifacts")
}
}
3 changes: 3 additions & 0 deletions build-logic/build.gradle.kts
@@ -0,0 +1,3 @@
plugins {
`embedded-kotlin` apply false
}
8 changes: 8 additions & 0 deletions build-logic/java-comment-preprocessor/build.gradle.kts
@@ -0,0 +1,8 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
implementation("com.igormaznitsa:jcp:7.0.2")
implementation("com.github.vlsi.gradle-extensions:com.github.vlsi.gradle-extensions.gradle.plugin:1.86")
}
@@ -0,0 +1,27 @@
import com.github.vlsi.gradle.dsl.configureEach
import com.github.vlsi.gradle.properties.dsl.props

plugins {
id("com.github.vlsi.gradle-extensions")
}

tasks.configureEach<buildlogic.JavaCommentPreprocessorTask> {
variables.apply {
val jdbcSpec = props.string("jdbc.specification.version")
put("mvn.project.property.postgresql.jdbc.spec", "JDBC$jdbcSpec")
put("jdbc.specification.version", jdbcSpec)
}

val re = Regex("^(\\d+)\\.(\\d+)(?:\\.(\\d+))?.*")

val version = project.version.toString()
val matchResult = re.find(version) ?: throw GradleException("Unable to parse major.minor.patch version parts from project.version '$version'")
val (major, minor, patch) = matchResult.destructured

variables.apply {
put("version", version)
put("version.major", major)
put("version.minor", minor)
put("version.patch", patch.ifBlank { "0" })
}
}
Expand Up @@ -3,7 +3,7 @@
* See the LICENSE file in the project root for more information.
*/

package org.postgresql.buildtools
package buildlogic

import com.igormaznitsa.jcp.JcpPreprocessor
import com.igormaznitsa.jcp.context.PreprocessorContext
Expand Down
17 changes: 17 additions & 0 deletions build-logic/jvm/build.gradle.kts
@@ -0,0 +1,17 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
implementation(project(":build-parameters"))
implementation(project(":verification"))
implementation("com.github.vlsi.crlf:com.github.vlsi.crlf.gradle.plugin:1.86")
implementation("com.github.vlsi.gradle-extensions:com.github.vlsi.gradle-extensions.gradle.plugin:1.86")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin")
implementation("com.igormaznitsa:jcp:7.0.2")
implementation("org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin:$embeddedKotlinVersion")
implementation("com.github.autostyle:com.github.autostyle.gradle.plugin:3.2")
implementation("net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:3.0.1")
implementation("com.github.vlsi.jandex:com.github.vlsi.jandex.gradle.plugin:1.86")
implementation("de.thetaphi.forbiddenapis:de.thetaphi.forbiddenapis.gradle.plugin:3.3")
}
@@ -0,0 +1,18 @@
plugins {
id("java-base")
id("org.jetbrains.dokka")
}

java {
// Workaround https://github.com/gradle/gradle/issues/21933, so it adds javadocElements configuration
withJavadocJar()
}

val dokkaJar by tasks.registering(Jar::class) {
group = LifecycleBasePlugin.BUILD_GROUP
description = "Assembles a jar archive containing javadoc"
from(tasks.dokkaJavadoc)
archiveClassifier.set("javadoc")
}

configurations[JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME].outgoing.artifact(dokkaJar)
@@ -0,0 +1,4 @@
plugins {
id("build-logic.java")
id("java-library")
}