Skip to content

Commit 468f3a9

Browse files
authored
Merge pull request #105 from jiakuan/feature/104-add-extra-source-dirs
Add extraSourceDirs capability for additional source directories
2 parents 743fb0f + aeb3bc0 commit 468f3a9

File tree

22 files changed

+471
-5
lines changed

22 files changed

+471
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Check out their latest Chrome extension, [MindPane](https://mindpane.net/), whic
2727
This refined tracking minimizes unnecessary recompilation by focusing solely
2828
on changes within GWT-specific code, optimizing the build process for faster
2929
iterations and more efficient resource usage.
30+
- **Extra source directories support** with `extraSourceDirs` property. Easily
31+
include additional source directories for GWT compilation, perfect for
32+
multi-module projects, annotation processor outputs, or generated sources.
3033
- **Configuration aligned with GWT compiler options** for ease of use
3134
- **Support for GWT 2.12+** and the latest Gradle 8.13 (minimum Gradle version is 8.1)
3235
- Built-in tasks for GWT compilation and dev mode
@@ -85,6 +88,10 @@ project:
8588
For the full list of available options, refer to
8689
the [Configuration](doc/latest/Configuration.md) documentation.
8790

91+
## Version History and Release Notes
92+
93+
For information about new features, bug fixes, and changes in each version, see the [GitHub Releases](https://github.com/jiakuan/gwt-gradle-plugin/releases) page.
94+
8895
## Version 1 (v1) Plugin
8996

9097
The original GWT Gradle Plugin (v1) source code is still available on

doc/latest/Best Practices.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ gwt {
8888
gen = file("${layout.buildDirectory}/gwt/gen")
8989
// Compile report as information for the GWT developer
9090
extra = file("${layout.buildDirectory}/gwt/extra")
91+
92+
// Optional: Include extra source directories from other modules
93+
// This is particularly useful in multi-module projects where you need
94+
// to include sources from shared modules or generated sources
95+
extraSourceDirs = files(
96+
"../shared-module/src/main/java",
97+
"src/generated/java"
98+
)
9199
}
92100
93101
// Additional configurations each holding a single zip file with
@@ -173,11 +181,78 @@ war {
173181

174182
With the above, the final war file will never have any GWT libraries packaged because it only depends on the GWT JS output. An alternative to using Gradle configurations is to use Gradle variants, but I think configurations are a bit easier to set up and are good enough in this situation here.
175183

176-
If youre not building a WAR file or are using a backend technology other than Java, you can configure the JavaScript output directory to point directly to your frontend folder.
184+
If you're not building a WAR file or are using a backend technology other than Java, you can configure the JavaScript output directory to point directly to your frontend folder.
177185

178186
```
179187
gwt {
180188
// ... other gwt configurations
181189
war = file('../my-frontend/scripts')
182190
}
183191
```
192+
193+
## Working with Additional Source Directories
194+
195+
### Using extraSourceDirs for Common Scenarios
196+
197+
The `extraSourceDirs` property is designed to handle various scenarios where you need to include additional Java source directories in your GWT compilation:
198+
199+
#### 1. Multi-Module Projects
200+
When working with multiple Gradle modules where one module contains shared code:
201+
202+
```gradle
203+
gwt {
204+
modules = ['com.example.MyApp']
205+
extraSourceDirs = files(
206+
project(':shared-core').file('src/main/java'),
207+
project(':shared-ui').file('src/main/java')
208+
)
209+
}
210+
```
211+
212+
#### 2. Annotation Processor Outputs
213+
For including generated sources from annotation processors:
214+
215+
```gradle
216+
gwt {
217+
modules = ['com.example.MyApp']
218+
extraSourceDirs = files('build/generated/sources/annotationProcessor/java/main')
219+
}
220+
```
221+
222+
#### 3. Generated Sources
223+
When you have custom code generation tasks:
224+
225+
```gradle
226+
task generateSources(type: Exec) {
227+
// Your source generation logic
228+
outputs.dir 'src/generated/java'
229+
}
230+
231+
gwt {
232+
modules = ['com.example.MyApp']
233+
extraSourceDirs = files('src/generated/java')
234+
}
235+
236+
// Ensure sources are generated before GWT compilation
237+
tasks.gwtCompile.dependsOn(generateSources)
238+
```
239+
240+
#### 4. Configuration-Specific Sources
241+
You can also configure different extra sources for different modes:
242+
243+
```gradle
244+
gwt {
245+
modules = ['com.example.MyApp']
246+
// Common extra sources
247+
extraSourceDirs = files('../shared/src/main/java')
248+
249+
compiler {
250+
// Additional sources only for compilation
251+
extraSourceDirs = files('../shared/src/main/java', 'src/compile-only/java')
252+
}
253+
254+
devMode {
255+
// Additional sources for development mode
256+
extraSourceDirs = files('../shared/src/main/java', 'src/debug/java')
257+
}
258+
}

doc/latest/Configuration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ gwt {
5656
// "-Dgwt.persistentunitcachedir=[YourCacheDir]" - The directory to use for the persistent unit cache
5757
cacheDir = file('build/gwt-unitCache')
5858
59+
// Optional: Additional source directories to include in GWT compilation and Java source sets.
60+
// These directories are automatically added to both the classpath and compilation process.
61+
// Useful for multi-module projects, annotation processor outputs, or generated sources.
62+
// Example: extraSourceDirs = files("path/to/extra/sources", "another/source/dir")
63+
extraSourceDirs = files('src/generated/java')
64+
5965
// Optional: Generate exports for JsInterop purposes. If no -includeJsInteropExport/-excludeJsInteropExport provided, generates all exports. (defaults to OFF)
6066
generateJsInteropExports = false
6167
@@ -90,6 +96,7 @@ gwt {
9096
compiler {
9197
//
9298
// All options in 'gwt' closure (except 'gwtVersion') can be overridden here
99+
// Including extraSourceDirs - useful for compile-specific additional sources
93100
//
94101
95102
// Optional: Enables Javascript output suitable for post-compilation by Closure Compiler (defaults to OFF)
@@ -136,6 +143,7 @@ gwt {
136143
devMode {
137144
//
138145
// All options in 'gwt' closure (except 'gwtVersion') can be overridden here
146+
// Including extraSourceDirs - useful for dev mode specific additional sources
139147
//
140148
141149
// Optional: Starts a servlet container serving the directory specified by the -war flag. (defaults to ON)
@@ -169,6 +177,7 @@ gwt {
169177
superDev {
170178
//
171179
// All options in 'gwt' closure (except 'gwtVersion') can be overridden here
180+
// Including extraSourceDirs - useful for super dev mode specific additional sources
172181
//
173182
174183
// Optional: Allows -src flags to reference missing directories. (defaults to OFF)

doc/latest/Quickstart.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,34 @@ the minimal configuration required to use the plugin:
4040
gwt {
4141
// e.g. modules = ['com.example.MyModule']
4242
modules = ['<YOUR-GWT-MODULE>']
43+
44+
// Optional: Add extra source directories for multi-module projects,
45+
// generated sources, or annotation processor outputs
46+
// extraSourceDirs = files("path/to/extra/sources")
4347
}
4448
```
4549

4650
Once you have enabled the plugin, you only need to specify the GWT module you
47-
want to compile. The plugin will take care of the rest. For more configuration
48-
options, refer to the [Configuration](Configuration.md) documentation.
51+
want to compile. The plugin will take care of the rest.
52+
53+
### Advanced Configuration
54+
55+
For projects with additional source directories (such as multi-module setups or
56+
generated sources), you can use the `extraSourceDirs` property:
57+
58+
```groovy
59+
gwt {
60+
modules = ['com.example.MyModule']
61+
62+
// Include additional source directories
63+
extraSourceDirs = files(
64+
"src/generated/java",
65+
"../shared-module/src/main/java"
66+
)
67+
}
68+
```
69+
70+
For more configuration options, refer to the [Configuration](Configuration.md) documentation.
4971

5072
## Build the project
5173

doc/version-1.x/version-history.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Version History
22

3+
**Note:** This version history is for the v1 plugin. For v2 plugin version history, please see the GitHub releases page.
4+
35
## 1.1+
46

57
Please see Github

examples/basic-gwt-project/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id 'java'
3-
id "org.docstr.gwt" version "2.2.4"
3+
id 'org.docstr.gwt' // version comes from included build
44
}
55

66
group = 'com.example'
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Extra Sources Example
2+
3+
This example demonstrates the `extraSourceDirs` feature of the GWT Gradle Plugin, which allows you to include additional source directories in your GWT compilation.
4+
5+
## Overview
6+
7+
The `extraSourceDirs` property is useful in several scenarios:
8+
9+
- **Multi-module projects**: Include sources from other Gradle modules
10+
- **Generated sources**: Include output from annotation processors or code generators
11+
- **Shared code**: Include common code that lives outside the main source tree
12+
- **Legacy code**: Include sources from non-standard directory structures
13+
14+
## Project Structure
15+
16+
```
17+
extra-sources-example/
18+
├── build.gradle # Main build configuration with extraSourceDirs
19+
├── extra-src/ # Additional source directory
20+
│ └── com/example/
21+
│ ├── Extra.gwt.xml # GWT module for extra sources
22+
│ └── extra/
23+
│ └── ExtraSourceClass.java
24+
└── src/main/java/
25+
└── com/example/
26+
├── MyModule.gwt.xml # Main GWT module
27+
├── client/
28+
│ └── MyEntryPoint.java
29+
└── shared/
30+
└── SharedClass.java
31+
```
32+
33+
## Configuration
34+
35+
The key configuration in `build.gradle`:
36+
37+
```gradle
38+
gwt {
39+
gwtVersion = '2.12.1'
40+
modules = ['com.example.MyModule']
41+
42+
// Example of adding extra source directories
43+
// These will be automatically added to both GWT compilation and Java source sets
44+
// This could be sources from another module or generated sources
45+
extraSourceDirs = files("$projectDir/extra-src")
46+
47+
compiler {
48+
style = 'PRETTY'
49+
}
50+
}
51+
```
52+
53+
## Key Features Demonstrated
54+
55+
### 1. Automatic Source Set Integration
56+
When you specify `extraSourceDirs`, the plugin automatically:
57+
- Adds the directories to the Java source sets
58+
- Includes them in the GWT compilation classpath
59+
- Ensures proper dependency tracking for incremental builds
60+
61+
### 2. Cross-Directory Module References
62+
The example shows how code in the main source directory can reference and use classes from the extra source directory:
63+
64+
- `ExtraSourceClass` in `extra-src/` is available to the main module
65+
- The GWT module can inherit from modules defined in extra source directories
66+
- All sources are compiled together seamlessly
67+
68+
### 3. Multiple Source Directories
69+
You can specify multiple extra source directories:
70+
71+
```gradle
72+
extraSourceDirs = files(
73+
"$projectDir/extra-src",
74+
"$projectDir/generated-src",
75+
"../shared-module/src/main/java"
76+
)
77+
```
78+
79+
## Usage Scenarios
80+
81+
### Multi-Module Projects
82+
```gradle
83+
// In a multi-module setup
84+
gwt {
85+
modules = ['com.example.MyApp']
86+
extraSourceDirs = files(
87+
project(':shared-core').file('src/main/java'),
88+
project(':shared-ui').file('src/main/java')
89+
)
90+
}
91+
```
92+
93+
### Generated Sources
94+
```gradle
95+
// Include annotation processor outputs
96+
gwt {
97+
modules = ['com.example.MyApp']
98+
extraSourceDirs = files('build/generated/sources/annotationProcessor/java/main')
99+
}
100+
```
101+
102+
### Custom Source Generation
103+
```gradle
104+
task generateSources(type: Exec) {
105+
// Your source generation logic
106+
outputs.dir 'src/generated/java'
107+
}
108+
109+
gwt {
110+
modules = ['com.example.MyApp']
111+
extraSourceDirs = files('src/generated/java')
112+
}
113+
114+
// Ensure sources are generated before GWT compilation
115+
tasks.gwtCompile.dependsOn(generateSources)
116+
```
117+
118+
## Running the Example
119+
120+
1. **Compile the project:**
121+
```bash
122+
./gradlew gwtCompile
123+
```
124+
125+
2. **Run in development mode:**
126+
```bash
127+
./gradlew gwtDevMode
128+
```
129+
130+
3. **Build the complete project:**
131+
```bash
132+
./gradlew build
133+
```
134+
135+
## Expected Output
136+
137+
When you run `gwtCompile`, you should see that:
138+
- Sources from both `src/main/java` and `extra-src` are included in compilation
139+
- The `ExtraSourceClass` is available to the main application
140+
- The GWT compiler successfully processes all sources together
141+
142+
## Advanced Configuration
143+
144+
### Per-Mode Configuration
145+
You can also configure different extra sources for different modes:
146+
147+
```gradle
148+
gwt {
149+
modules = ['com.example.MyApp']
150+
extraSourceDirs = files('common-extra-src')
151+
152+
compiler {
153+
extraSourceDirs = files('common-extra-src', 'compile-only-src')
154+
}
155+
156+
devMode {
157+
extraSourceDirs = files('common-extra-src', 'dev-only-src')
158+
}
159+
}
160+
```
161+
162+
### With FileCollections
163+
You can use Gradle's `FileCollection` for more complex scenarios:
164+
165+
```gradle
166+
configurations {
167+
extraSources
168+
}
169+
170+
dependencies {
171+
extraSources files('path1', 'path2')
172+
extraSources project(':other-module').sourceSets.main.java.srcDirs
173+
}
174+
175+
gwt {
176+
modules = ['com.example.MyApp']
177+
extraSourceDirs = configurations.extraSources
178+
}
179+
```
180+
181+
This example demonstrates the flexibility and power of the `extraSourceDirs` feature for handling complex project structures and source management scenarios.

0 commit comments

Comments
 (0)