Skip to content

Commit 70b8cf9

Browse files
committed
Add initial documentation for Module Info DSL
1 parent 040d7de commit 70b8cf9

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Java Module Dependencies Gradle Plugin - Changelog
22

3+
## Version 1.4
4+
* [#31](https://github.com/gradlex-org/java-module-dependencies/issues/31) DSL for module dependencies that cannot be defined in module-info
5+
36
## Version 1.3.1
47

58
* Fix integration with analysis plugin if root projects are involved

README.MD

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ module org.example.mymodule {
8484

8585
Note that `requires /*runtime*/` is a directive specifically supported by this plugin to allow the specification of _runtime only_ dependencies.
8686

87+
## Define additional module dependencies in build files
88+
89+
With this plugin you move dependency definitions into `module-info.java` files and no longer use the `dependencies {}` block in build files.
90+
However, there are certain dependency "scopes" not supported by the `module-info.java` syntax.
91+
For this, the plugin offers an extension of Gradle's DSL to be used in `build.gradle(.kts)` files.
92+
93+
```
94+
mainModuleInfo {
95+
runtimeOnly("org.slf4j.simple") // runtime only dependency for the 'main' module
96+
annotationProcessor("dagger.compiler") // annotation processor dependency for the 'main' module
97+
}
98+
```
99+
100+
For modules in other source sets, there are corresponding blocks to define dependencies if needed – e.g. `testFixturesModuleInfo {}`.
101+
102+
In case a source set does **not** contain a `module-info.java`, all dependencies can be defined in the `build.gradle(.kts)` files.
103+
The only case where this should be used is for whitebox testing activated via the [org.gradlex.java-module-testing](https://github.com/gradlex-org/java-module-testing) plugin.
104+
105+
```
106+
testModuleInfo {
107+
requires("org.assertj.core")
108+
requires("org.hamcrest")
109+
requires("org.junit.jupiter.api")
110+
}
111+
```
112+
87113
## Add Module Name mapping information (if needed)
88114

89115
You may define additional mappings from _Module Name_ to _group:name (GA) coordinates_.
@@ -98,7 +124,6 @@ You can define additional entries (or overwrite entries from the plugin) as foll
98124
```
99125
// optional configuration if required
100126
javaModuleDependencies {
101-
// Make an automatic module known
102127
moduleNameToGA.put("org.apache.commons.lang3", "org.apache.commons:commons-lang3")
103128
}
104129
```
@@ -124,7 +149,8 @@ If you have a `prefixOfYourChoice`, all your Modules **need to have the same pre
124149
## Define Module versions in a Platform project as Dependency Constraints
125150

126151
Use Gradle's dependency constraints and/or platforms to define versions for the modules you depend on.
127-
Inside a `javaModuleDependencies { }` block, you can use the `gav("module.name", "1.0")` notation to define a version by Module Name instead of coordinates.
152+
For that the plugin offers a `moduleInfo { }` block in `java-platform` projects.
153+
In that block, you have the `version("module.name", "1.0")` notation to define a version by Module Name instead of coordinates.
128154
For libraries that consist of multiple components and have a BOM for version management, you might prefer to include the BOM, which you need to do by coordinates, because a BOM does not have a Module Name.
129155

130156
```
@@ -134,12 +160,10 @@ plugins {
134160
}
135161
136162
// Define versions for Modules via the Module Name
137-
dependencies.constraints {
138-
javaModuleDependencies {
139-
api(gav("org.apache.xmlbeans", "5.0.1"))
140-
api(gav("org.slf4j", "1.7.28"))
141-
api(gav("org.slf4j.simple", "1.7.28"))
142-
}
163+
moduleInfo {
164+
version("org.apache.xmlbeans", "5.0.1")
165+
version("org.slf4j", "2.0.7")
166+
version("org.slf4j.simple", "2.0.7")
143167
}
144168
145169
// Use BOMs for Modules that are part of a library of multiple Modules
@@ -205,22 +229,20 @@ $ ./gradlew :app:recommendModuleVersions -q
205229
206230
Latest Stable Versions of Java Modules - use in your platform project's build.gradle(.kts)
207231
==========================================================================================
208-
dependencies.constraints {
209-
javaModuleDependencies {
210-
api(gav("com.fasterxml.jackson.annotation", "2.13.2"))
211-
api(gav("com.fasterxml.jackson.core", "2.13.2"))
212-
api(gav("com.fasterxml.jackson.databind", "2.13.2.2"))
213-
api(gav("org.apache.logging.log4j", "2.17.2"))
214-
api(gav("org.apache.xmlbeans", "5.0.3"))
215-
api(gav("org.junit.jupiter.api", "5.8.2"))
216-
api(gav("org.junit.jupiter.engine", "5.8.2"))
217-
api(gav("org.junit.platform.commons", "1.8.2"))
218-
api(gav("org.junit.platform.engine", "1.8.2"))
219-
api(gav("org.junit.platform.launcher", "1.8.2"))
220-
api(gav("org.opentest4j", "1.2.0"))
221-
api(gav("org.slf4j", "1.7.36"))
222-
api(gav("org.slf4j.simple", "1.7.36"))
223-
}
232+
moduleInfo {
233+
version("com.fasterxml.jackson.annotation", "2.13.2")
234+
version("com.fasterxml.jackson.core", "2.13.2")
235+
version("com.fasterxml.jackson.databind", "2.13.2.2")
236+
version("org.apache.logging.log4j", "2.17.2")
237+
version("org.apache.xmlbeans", "5.0.3")
238+
version("org.junit.jupiter.api", "5.8.2")
239+
version("org.junit.jupiter.engine", "5.8.2")
240+
version("org.junit.platform.commons", "1.8.2")
241+
version("org.junit.platform.engine", "1.8.2")
242+
version("org.junit.platform.launcher", "1.8.2")
243+
version("org.opentest4j", "1.2.0")
244+
version("org.slf4j", "1.7.36")
245+
version("org.slf4j.simple", "1.7.36")
224246
}
225247
```
226248

0 commit comments

Comments
 (0)