You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {
84
86
85
87
Note that `requires /*runtime*/` is a directive specifically supported by this plugin to allow the specification of _runtime only_ dependencies.
86
88
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
+
87
115
## Add Module Name mapping information (if needed)
88
116
89
117
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
@@ -124,7 +151,8 @@ If you have a `prefixOfYourChoice`, all your Modules **need to have the same pre
124
151
## Define Module versions in a Platform project as Dependency Constraints
125
152
126
153
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.
128
156
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.
129
157
130
158
```
@@ -134,12 +162,10 @@ plugins {
134
162
}
135
163
136
164
// 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")
143
169
}
144
170
145
171
// Use BOMs for Modules that are part of a library of multiple Modules
0 commit comments