Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#51 Add jpms module-info using Multi-Release jar #59

Merged
merged 5 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions inject-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -76,6 +66,28 @@
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>

<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC1</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<jvmVersion>9</jvmVersion>
<module>
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
</module>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
8 changes: 8 additions & 0 deletions inject-generator/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module io.avaje.inject.generator {

requires java.compiler;
requires java.annotation;
requires io.avaje.inject;
rbygrave marked this conversation as resolved.
Show resolved Hide resolved

provides javax.annotation.processing.Processor with io.avaje.inject.generator.Processor;
}
2 changes: 0 additions & 2 deletions inject-generator/src/main/resources/META-INF/MANIFEST.MF

This file was deleted.

30 changes: 22 additions & 8 deletions inject/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# DInject
# Avaje Inject
APT based dependency injection for server side developers - https://dinject.io

### Example module use

```java
module org.example {

requires javax.inject;
requires org.slf4j;
rbygrave marked this conversation as resolved.
Show resolved Hide resolved
requires transitive io.avaje.inject;
rbygrave marked this conversation as resolved.
Show resolved Hide resolved

// register org.example._di$Factory from generated sources
provides io.avaje.inject.core.BeanContextFactory with org.example._di$Factory;
}
```

## Similar to Dagger (https://google.github.io/dagger/)

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


## Differences to Dagger
## Differences to Dagger

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


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

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

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

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


## Plans

- Additionally library for reading configuration / application.yaml
- Additionally library for reading configuration / application.yaml
- Configuration supports onChange listening (aka dynamic configuration API)
26 changes: 18 additions & 8 deletions inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,24 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC1</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<jvmVersion>9</jvmVersion>
<module>
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
</module>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
4 changes: 3 additions & 1 deletion inject/src/main/java/io/avaje/inject/BeanContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ public BeanContext build() {

Set<String> moduleNames = factoryOrder.orderFactories();
if (moduleNames.isEmpty()) {
throw new IllegalStateException("No modules found suggests using Gradle and IDEA but with a setup issue?" +
throw new IllegalStateException("No modules found. When using java module system we need an explicit provides clause in module-info like:\n\n" +
" provides io.avaje.inject.core.BeanContextFactory with org.example._di$Factory;\n\n" +
" Otherwise perhaps using Gradle and IDEA but with a setup issue?" +
" Review IntelliJ Settings / Build / Build tools / Gradle - 'Build and run using' value and set that to 'Gradle'. " +
" Refer to https://dinject.io/docs/gradle#idea");
}
Expand Down
12 changes: 12 additions & 0 deletions inject/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module io.avaje.inject {

exports io.avaje.inject;
exports io.avaje.inject.core;

requires javax.inject;
requires org.slf4j;
requires static org.mockito;
rbygrave marked this conversation as resolved.
Show resolved Hide resolved

uses io.avaje.inject.core.BeanContextFactory;

}
2 changes: 0 additions & 2 deletions inject/src/main/resources/META-INF/MANIFEST.MF

This file was deleted.