From 3fa1380862360b424852c2417080013b863c286f Mon Sep 17 00:00:00 2001 From: Fabian Windheuser Date: Mon, 24 Jan 2022 12:48:47 +0000 Subject: [PATCH 1/2] Prefer project modules on dependency resolution per default --- README.md | 37 ++++++++++--------- gradle-baseline-java/build.gradle | 7 ++++ .../palantir/baseline/plugins/Baseline.java | 1 + .../plugins/BaselinePreferProjectModules.java | 33 +++++++++++++++++ 4 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselinePreferProjectModules.java diff --git a/README.md b/README.md index 4142fa4d9..7ae4260eb 100644 --- a/README.md +++ b/README.md @@ -8,24 +8,25 @@ _Baseline is a family of Gradle plugins for configuring Java projects with sensible defaults for code-style, static analysis, dependency versioning, CircleCI and IntelliJ IDEA/Eclipse integration._ -| Plugin | Description | -|-----------------------------------------------|------------------------| -| `com.palantir.baseline-idea` | Configures [Intellij IDEA](https://www.jetbrains.com/idea/) with code style and copyright headers -| `com.palantir.baseline-eclipse` | Configures [Eclipse](https://www.eclipse.org/downloads/) with code style and copyright headers -| `com.palantir.baseline-error-prone` | Static analysis for your Java code using Google's [error-prone](http://errorprone.info/). -| `com.palantir.baseline-checkstyle` | Enforces consistent Java formatting using [checkstyle](http://checkstyle.sourceforge.io/) -| `com.palantir.baseline-format` | Formats your java files to comply with checkstyle -| `com.palantir.baseline-scalastyle` | Enforces formatting using [scalastyle](https://github.com/scalastyle/scalastyle) -| `com.palantir.baseline-class-uniqueness` | Analyses your classpath to ensure no fully-qualified class is defined more than once. -| `com.palantir.baseline-circleci` | [CircleCI](https://circleci.com/) integration using `$CIRCLE_ARTIFACTS` and `$CIRCLE_TEST_REPORTS` dirs -| `com.palantir.baseline-config` | Config files for the above plugins -| `com.palantir.baseline-reproducibility` | Sensible defaults to ensure Jar, Tar and Zip tasks can be reproduced -| `com.palantir.baseline-exact-dependencies` | Ensures projects explicitly declare all the dependencies they rely on, no more and no less -| `com.palantir.baseline-encoding` | Ensures projects use the UTF-8 encoding in compile tasks. -| `com.palantir.baseline-release-compatibility` | Ensures projects targeting older JREs only compile against classes and methods available in those JREs. -| `com.palantir.baseline-testing` | Configures test tasks to dump heap dumps (hprof files) for convenient debugging -| `com.palantir.baseline-immutables` | Enables incremental compilation for the [Immutables](http://immutables.github.io/) annotation processor. -| `com.palantir.baseline-java-versions` | Configures JDK versions in a consistent way via Gradle Toolchains. +| Plugin | Description | +|------------------------------------------------|------------------------| +| `com.palantir.baseline-idea` | Configures [Intellij IDEA](https://www.jetbrains.com/idea/) with code style and copyright headers +| `com.palantir.baseline-eclipse` | Configures [Eclipse](https://www.eclipse.org/downloads/) with code style and copyright headers +| `com.palantir.baseline-error-prone` | Static analysis for your Java code using Google's [error-prone](http://errorprone.info/). +| `com.palantir.baseline-checkstyle` | Enforces consistent Java formatting using [checkstyle](http://checkstyle.sourceforge.io/) +| `com.palantir.baseline-format` | Formats your java files to comply with checkstyle +| `com.palantir.baseline-scalastyle` | Enforces formatting using [scalastyle](https://github.com/scalastyle/scalastyle) +| `com.palantir.baseline-class-uniqueness` | Analyses your classpath to ensure no fully-qualified class is defined more than once. +| `com.palantir.baseline-circleci` | [CircleCI](https://circleci.com/) integration using `$CIRCLE_ARTIFACTS` and `$CIRCLE_TEST_REPORTS` dirs +| `com.palantir.baseline-config` | Config files for the above plugins +| `com.palantir.baseline-reproducibility` | Sensible defaults to ensure Jar, Tar and Zip tasks can be reproduced +| `com.palantir.baseline-exact-dependencies` | Ensures projects explicitly declare all the dependencies they rely on, no more and no less +| `com.palantir.baseline-encoding` | Ensures projects use the UTF-8 encoding in compile tasks. +| `com.palantir.baseline-release-compatibility` | Ensures projects targeting older JREs only compile against classes and methods available in those JREs. +| `com.palantir.baseline-testing` | Configures test tasks to dump heap dumps (hprof files) for convenient debugging +| `com.palantir.baseline-immutables` | Enables incremental compilation for the [Immutables](http://immutables.github.io/) annotation processor. +| `com.palantir.baseline-java-versions` | Configures JDK versions in a consistent way via Gradle Toolchains. +| `com.palantir.baseline-prefer-project-modules` | Configures Gradle to prefer project modules over external modules on dependency resolution per default. See also the [Baseline Java Style Guide and Best Practices](./docs). diff --git a/gradle-baseline-java/build.gradle b/gradle-baseline-java/build.gradle index 8152d8e46..d585933ca 100644 --- a/gradle-baseline-java/build.gradle +++ b/gradle-baseline-java/build.gradle @@ -90,6 +90,10 @@ gradlePlugin { id = 'com.palantir.baseline-enable-preview-flag' implementationClass = 'com.palantir.baseline.plugins.BaselineEnablePreviewFlag' } + baselinePreferProjectModules { + id = 'com.palantir.baseline-prefer-project-modules' + implementationClass = 'com.palantir.baseline.plugins.BaselinePreferProjectModules' + } } } @@ -130,6 +134,9 @@ pluginBundle { baselineEnablePreviewFlag { displayName = 'Palantir Baseline --enable-preview Flag Plugin' } + baselinePreferProjectModules { + displayName = 'Palantir Baseline Prefer Project Modules Plugin' + } } } diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java index 260d73475..467f8ffd3 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java @@ -61,6 +61,7 @@ public void apply(Project project) { proj.getPluginManager().apply(BaselineJavaParameters.class); proj.getPluginManager().apply(BaselineImmutables.class); proj.getPluginManager().apply(BaselineModuleJvmArgs.class); + proj.getPluginManager().apply(BaselinePreferProjectModules.class); }); } } diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselinePreferProjectModules.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselinePreferProjectModules.java new file mode 100644 index 000000000..56c5ad8eb --- /dev/null +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselinePreferProjectModules.java @@ -0,0 +1,33 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. 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. + */ + +package com.palantir.baseline.plugins; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.ResolutionStrategy; + +/** + * Prefer project modules that are part of this build over external modules on dependency resolution. + */ +public final class BaselinePreferProjectModules implements Plugin { + @Override + public void apply(Project project) { + project.getConfigurations() + .configureEach( + configuration -> configuration.resolutionStrategy(ResolutionStrategy::preferProjectModules)); + } +} From 0461a1f8e00c20fa0df32cbd7df65f76cf010a29 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Mon, 24 Jan 2022 13:27:27 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-2056.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-2056.v2.yml diff --git a/changelog/@unreleased/pr-2056.v2.yml b/changelog/@unreleased/pr-2056.v2.yml new file mode 100644 index 000000000..360d51fd0 --- /dev/null +++ b/changelog/@unreleased/pr-2056.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Prefer project modules on dependency resolution per default + links: + - https://github.com/palantir/gradle-baseline/pull/2056