Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/griffio/dagger2-example
dagger2 (2.13) with gradle example
https://github.com/griffio/dagger2-example
dagger2 gradle
Last synced: 8 days ago
JSON representation
dagger2 (2.13) with gradle example
- Host: GitHub
- URL: https://github.com/griffio/dagger2-example
- Owner: griffio
- Created: 2015-01-01T04:23:33.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-08T20:43:04.000Z (about 7 years ago)
- Last Synced: 2024-04-16T18:26:59.983Z (7 months ago)
- Topics: dagger2, gradle
- Language: Java
- Homepage:
- Size: 119 KB
- Stars: 21
- Watchers: 6
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
dagger2-example with Gradle build
=================================[Dagger2 site ](http://google.github.io/dagger/)
[See branch for ewerk plugin version](https://github.com/griffio/dagger2-example/tree/plugin)
Since 2.0 release:- Dagger generates components prefixed with just "Dagger" instead of "_"
[Truth Assert](http://google.github.io/truth/)
Currently uses Truth.assertThat(...)
---
* @Component
* @Module
* @ProvidesThe TerrestrialPlanetsModule, for example, provides a singleton named "Mercury" etc.
```java
@Module
public class TerrestrialPlanetsModule {@Provides
@Singleton
@Named("Mercury")
Planet first() {
return new Mercury();
}@Provides
@Singleton
@Named("Venus")
Planet second() {
return new Venus();
}@Provides
@Singleton
@Named("Earth")
Planet third() {
return new Earth();
}@Provides
@Singleton
@Named("Mars")
Planet fourth() {
return new Mars();
}}
```
* Outer Planets module
* Jupiter
* Saturn
* Uranus
* Neptune* Dwarf Planets module
* Ceres
* Pluto
* Haumea
* MakeMake
* Eris
---**Gradle build**
* The dagger compiler (com.google.dagger:dagger-compiler) annotation processor is only added to the java compiler task classpath using the configuration "compileDagger".
* Application only runs with (com.google.dagger:dagger, javax.inject and com.google.guava as used in the application)
* The sourceSet for generated code is under 'src/dagger/java'
```
./gradlew run
``````groovy
plugins {
id 'java'
id 'application'
id "com.github.johnrengelman.shadow" version "1.2.3"
}project.ext.sourceCompatibility = JavaVersion.VERSION_1_8
project.ext.targetCompatibility = JavaVersion.VERSION_1_8repositories {
jcenter()
}sourceSets {
dagger {
java {
srcDirs = ['src/dagger/java']
}
}
}configurations {
compileDagger
}compileJava {
description = "dagger annotation processor is loaded automatically from classpath"
sourceSets.dagger.java.srcDirs*.mkdirs()
classpath += configurations.compileDagger
options.compilerArgs += [
'-s', sourceSets.dagger.java.srcDirs.iterator().next()
]
}mainClassName = "griffio.MainApplication"
clean {
description = "delete files in generated source directory tree"
delete fileTree(dir: sourceSets.dagger.java.srcDirs.iterator().next())
}dependencies {
compile(
"com.google.dagger:dagger:2.13",
"com.google.guava:guava:20.0")compileDagger(
"com.google.dagger:dagger-compiler:2.11")testCompile(
"junit:junit:4.12",
"com.google.truth:truth:0.30"
)}
task wrapper(type: Wrapper) {
gradleVersion = '2.3.1'
}
```