Skip to content

Commit 9a0e249

Browse files
authored
#51 Add jpms module-info using Multi-Release jar (#59)
* #51 Add jpms module-info using Multi-Release jar * #53 - Improve error message for JPMS use and no modules. * #53 - Make javax.inject and org.slf4j transitive. Fix associated readme example. * #53 - Add explicit requires javax.inject to avaje-inject-generator * #53 - Tidy avaje-inject-generator module-info, remove javax.inject as brought in transitively
1 parent 62d9c52 commit 9a0e249

File tree

8 files changed

+83
-37
lines changed

8 files changed

+83
-37
lines changed

inject-generator/pom.xml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<version>1.6-SNAPSHOT</version>
2020
</dependency>
2121

22-
<dependency>
23-
<groupId>javax.inject</groupId>
24-
<artifactId>javax.inject</artifactId>
25-
<version>1</version>
26-
</dependency>
27-
2822
<dependency>
2923
<groupId>javax.annotation</groupId>
3024
<artifactId>javax.annotation-api</artifactId>
@@ -44,16 +38,6 @@
4438

4539
<build>
4640
<plugins>
47-
<plugin>
48-
<groupId>org.apache.maven.plugins</groupId>
49-
<artifactId>maven-jar-plugin</artifactId>
50-
<version>3.1.0</version>
51-
<configuration>
52-
<archive>
53-
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
54-
</archive>
55-
</configuration>
56-
</plugin>
5741

5842
<plugin>
5943
<groupId>org.apache.maven.plugins</groupId>
@@ -66,6 +50,28 @@
6650
<compilerArgument>-proc:none</compilerArgument>
6751
</configuration>
6852
</plugin>
53+
54+
<plugin>
55+
<groupId>org.moditect</groupId>
56+
<artifactId>moditect-maven-plugin</artifactId>
57+
<version>1.0.0.RC1</version>
58+
<executions>
59+
<execution>
60+
<id>add-module-infos</id>
61+
<phase>package</phase>
62+
<goals>
63+
<goal>add-module-info</goal>
64+
</goals>
65+
<configuration>
66+
<jvmVersion>9</jvmVersion>
67+
<module>
68+
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
69+
</module>
70+
</configuration>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
6975
</plugins>
7076
</build>
7177

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module io.avaje.inject.generator {
2+
3+
requires java.compiler;
4+
requires io.avaje.inject;
5+
requires java.annotation;
6+
7+
provides javax.annotation.processing.Processor with io.avaje.inject.generator.Processor;
8+
}

inject-generator/src/main/resources/META-INF/MANIFEST.MF

Lines changed: 0 additions & 2 deletions
This file was deleted.

inject/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
# DInject
1+
# Avaje Inject
22
APT based dependency injection for server side developers - https://dinject.io
33

4+
### Example module use
5+
6+
```java
7+
module org.example {
8+
9+
requires io.avaje.inject;
10+
11+
// register org.example._di$Factory from generated sources
12+
provides io.avaje.inject.core.BeanContextFactory with org.example._di$Factory;
13+
}
14+
```
15+
416
## Similar to Dagger (https://google.github.io/dagger/)
517

618
- Uses Java annotation processing for dependency injection
@@ -9,34 +21,34 @@ APT based dependency injection for server side developers - https://dinject.io
921
- A `Library only` (a DI library and that's it ~25k in size)
1022

1123

12-
## Differences to Dagger
24+
## Differences to Dagger
1325

1426
- Aimed specifically for server side development (rather than Andriod)
1527
- Supports lifecycle methods with `@PostConstruct` and `@PreDestory`
1628
- Supports `@Factory` and `@Bean`
17-
- Provides API to obtain all bean instances that implement an interface
29+
- Provides API to obtain all bean instances that implement an interface
1830
- Provides API to obtain all bean instances that have an annotation
1931
- Integration with server side web frameworks like Rapidoid, Sparkjava, Javlin etc
20-
32+
2133

2234
## Differences to Micronaut DI (https://docs.micronaut.io/latest/guide/index.html#ioc)
2335

2436
- DInject generates source code rather that bytecode
2537
- DInject generates construction order at compile time
2638
- DInject is aiming to be a `Library only` (so a DI library and that's it without any dependencies)
27-
- DInject is expected to stay a lot smaller with minimal dependencies
39+
- DInject is expected to stay a lot smaller with minimal dependencies
2840
- DInject is expected to be a lot faster (due to the pre-ordering of construction in generated code)
2941

3042
## Differences to Spring DI (https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html)
3143

3244
- DInject only has Singleton scope
3345
- DInject doesn't yet have support for something like `@Value`
3446
- DInject provides similar DI features but with code generation via APT
35-
and hence much lower startup time and much lower cost (so better suited to micro-services).
36-
- No use of reflection or scanning even for multi-module dependency injection
47+
and hence much lower startup time and much lower cost (so better suited to micro-services).
48+
- No use of reflection or scanning even for multi-module dependency injection
3749

3850

3951
## Plans
4052

41-
- Additionally library for reading configuration / application.yaml
53+
- Additionally library for reading configuration / application.yaml
4254
- Configuration supports onChange listening (aka dynamic configuration API)

inject/pom.xml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,24 @@
5353
<build>
5454
<plugins>
5555
<plugin>
56-
<groupId>org.apache.maven.plugins</groupId>
57-
<artifactId>maven-jar-plugin</artifactId>
58-
<version>3.1.0</version>
59-
<configuration>
60-
<archive>
61-
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
62-
</archive>
63-
</configuration>
56+
<groupId>org.moditect</groupId>
57+
<artifactId>moditect-maven-plugin</artifactId>
58+
<version>1.0.0.RC1</version>
59+
<executions>
60+
<execution>
61+
<id>add-module-infos</id>
62+
<phase>package</phase>
63+
<goals>
64+
<goal>add-module-info</goal>
65+
</goals>
66+
<configuration>
67+
<jvmVersion>9</jvmVersion>
68+
<module>
69+
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
70+
</module>
71+
</configuration>
72+
</execution>
73+
</executions>
6474
</plugin>
6575
</plugins>
6676
</build>

inject/src/main/java/io/avaje/inject/BeanContextBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ public BeanContext build() {
360360

361361
Set<String> moduleNames = factoryOrder.orderFactories();
362362
if (moduleNames.isEmpty()) {
363-
throw new IllegalStateException("No modules found suggests using Gradle and IDEA but with a setup issue?" +
363+
throw new IllegalStateException("No modules found. When using java module system we need an explicit provides clause in module-info like:\n\n" +
364+
" provides io.avaje.inject.core.BeanContextFactory with org.example._di$Factory;\n\n" +
365+
" Otherwise perhaps using Gradle and IDEA but with a setup issue?" +
364366
" Review IntelliJ Settings / Build / Build tools / Gradle - 'Build and run using' value and set that to 'Gradle'. " +
365367
" Refer to https://dinject.io/docs/gradle#idea");
366368
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module io.avaje.inject {
2+
3+
exports io.avaje.inject;
4+
exports io.avaje.inject.core;
5+
6+
requires transitive javax.inject;
7+
requires transitive org.slf4j;
8+
requires static org.mockito;
9+
10+
uses io.avaje.inject.core.BeanContextFactory;
11+
12+
}

inject/src/main/resources/META-INF/MANIFEST.MF

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)