diff --git a/CHANGELOG.md b/CHANGELOG.md index 773b4d1..63b885f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. ## Unreleased -- / +- added `localImplementation` and `testLocalImplementation` to load dependencies into compile & runtime classpath without being transitive for consumers ## [1.0.1] - 2024-09-04 diff --git a/README.md b/README.md index 9da87b0..7ceb64b 100644 --- a/README.md +++ b/README.md @@ -433,9 +433,10 @@ The [Java plugin] ships some default configurations. Almost Gradle offers additional configurations. -| Configuration | Compile | Runtime | Transitive | -|----------------|:-------:|:-------:|:----------:| -| `localRuntime` | ❌ | ✔️ | None | +| Configuration | Compile | Runtime | Transitive | +|-----------------------|:-------:|:-------:|:----------:| +| `localRuntime` | ❌ | ✔️ | None | +| `localImplementation` | ️️ ✔️ | ✔️ | None | ## Test Configurations diff --git a/src/main/java/com/almostreliable/almostgradle/AlmostGradlePlugin.java b/src/main/java/com/almostreliable/almostgradle/AlmostGradlePlugin.java index 29b248c..8aa48dd 100644 --- a/src/main/java/com/almostreliable/almostgradle/AlmostGradlePlugin.java +++ b/src/main/java/com/almostreliable/almostgradle/AlmostGradlePlugin.java @@ -17,6 +17,15 @@ public void apply(Project project) { Utils.createLocalRuntime(project, JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, null); Utils.createLocalRuntime(project, JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, "test"); + Utils.createLocalImplementation(project, + JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, + JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME, + null); + Utils.createLocalImplementation(project, + JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, + JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME, + "test"); + project.getTasks().withType(JavaCompile.class).whenTaskAdded(javaCompile -> { javaCompile.getOptions().setEncoding("UTF-8"); }); diff --git a/src/main/java/com/almostreliable/almostgradle/Utils.java b/src/main/java/com/almostreliable/almostgradle/Utils.java index 57b86f4..010b24b 100644 --- a/src/main/java/com/almostreliable/almostgradle/Utils.java +++ b/src/main/java/com/almostreliable/almostgradle/Utils.java @@ -36,6 +36,17 @@ public static Configuration createLocalRuntime(Project project, String classPath }); } + public static void createLocalImplementation(Project project, String compileClassPathConfigName, String runtimeClassPathConfigName, @Nullable String prefix) { + String name = prefix == null ? "localImplementation" : prefix + "LocalImplementation"; + project.getConfigurations().create(name, c -> { + c.setVisible(true); + c.setCanBeResolved(true); + c.setCanBeConsumed(false); + project.getConfigurations().getByName(compileClassPathConfigName).extendsFrom(c); + project.getConfigurations().getByName(runtimeClassPathConfigName).extendsFrom(c); + }); + } + public static void log(Project project, String key, Object value) { project.getLogger().lifecycle(String.format("%-25s -> %s", key, value)); }