Skip to content

Commit

Permalink
add configuration for local implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Sep 5, 2024
1 parent 347cc6c commit feb25b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/almostreliable/almostgradle/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit feb25b4

Please sign in to comment.