Skip to content

Commit b1270ee

Browse files
committed
Add initial documentation for Module Info DSL
1 parent 0c11909 commit b1270ee

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-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: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ that shows all plugins in combination.
4242
For a quick start, you can find some samples here:
4343
* [samples/versions-in-platform](samples/versions-in-platform)
4444
* [samples/versions-in-catalog](samples/versions-in-catalog)
45+
* [samples/module-info-dsl](samples/module-info-dsl)
46+
* [samples/module-info-dsl-no-platform](samples/module-info-dsl-no-platform)
4547
* [samples/kotlin](samples/kotlin)
4648

4749
For general information about how to structure Gradle builds and apply community plugins like this one to all subprojects
@@ -84,6 +86,32 @@ module org.example.mymodule {
8486

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

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

89117
You may define additional mappings from _Module Name_ to _group:name (GA) coordinates_.
@@ -98,7 +126,6 @@ You can define additional entries (or overwrite entries from the plugin) as foll
98126
```
99127
// optional configuration if required
100128
javaModuleDependencies {
101-
// Make an automatic module known
102129
moduleNameToGA.put("org.apache.commons.lang3", "org.apache.commons:commons-lang3")
103130
}
104131
```
@@ -124,7 +151,8 @@ If you have a `prefixOfYourChoice`, all your Modules **need to have the same pre
124151
## Define Module versions in a Platform project as Dependency Constraints
125152

126153
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.
154+
For that the plugin offers a `moduleInfo { }` block in `java-platform` projects.
155+
In that block, you have the `version("module.name", "1.0")` notation to define a version by Module Name instead of coordinates.
128156
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.
129157

130158
```
@@ -134,12 +162,10 @@ plugins {
134162
}
135163
136164
// 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-
}
165+
moduleInfo {
166+
version("org.apache.xmlbeans", "5.0.1")
167+
version("org.slf4j", "2.0.7")
168+
version("org.slf4j.simple", "2.0.7")
143169
}
144170
145171
// Use BOMs for Modules that are part of a library of multiple Modules
@@ -205,22 +231,20 @@ $ ./gradlew :app:recommendModuleVersions -q
205231
206232
Latest Stable Versions of Java Modules - use in your platform project's build.gradle(.kts)
207233
==========================================================================================
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-
}
234+
moduleInfo {
235+
version("com.fasterxml.jackson.annotation", "2.13.2")
236+
version("com.fasterxml.jackson.core", "2.13.2")
237+
version("com.fasterxml.jackson.databind", "2.13.2.2")
238+
version("org.apache.logging.log4j", "2.17.2")
239+
version("org.apache.xmlbeans", "5.0.3")
240+
version("org.junit.jupiter.api", "5.8.2")
241+
version("org.junit.jupiter.engine", "5.8.2")
242+
version("org.junit.platform.commons", "1.8.2")
243+
version("org.junit.platform.engine", "1.8.2")
244+
version("org.junit.platform.launcher", "1.8.2")
245+
version("org.opentest4j", "1.2.0")
246+
version("org.slf4j", "1.7.36")
247+
version("org.slf4j.simple", "1.7.36")
224248
}
225249
```
226250

0 commit comments

Comments
 (0)