Sitelet https://github.com/griffio/dagger2-example/tree/plugin
Skip to content
 
 

Latest commit

 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dagger2-example with Gradle build

Dagger2 site

Since 2.0 release:- Dagger generates components prefixed with just "Dagger" instead of "_"

Truth Assert

Currently uses Truth.assertThat(...)


  • @Component
    • @Module
      • @Provides

The TerrestrialPlanetsModule, for example, provides a singleton named "Mercury" etc.

@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 forth() {
        return new Mars();
    }

}
  • Outer Planets module
    • Jupiter
    • Saturn
    • Uranus
    • Neptune

Gradle build

./gradlew run
plugins {
  id 'java'
  id 'application'
  id "com.github.johnrengelman.shadow" version "1.2.1"
  id "com.ewerk.gradle.plugins.dagger" version "1.0.0"
}

project.ext.sourceCompatibility = JavaVersion.VERSION_1_8
project.ext.targetCompatibility = JavaVersion.VERSION_1_8

repositories {
  jcenter()
  maven {
    url "https://oss.sonatype.org/content/repositories/snapshots"
  }
}

mainClassName = "griffio.MainApplication"

dependencies {

  compile(
      "com.google.guava:guava:18.0")

  testCompile(
      "junit:junit:4.12",
      "com.google.truth:truth:1.0-SNAPSHOT"
  )

}

task wrapper(type: Wrapper) {
  gradleVersion = '2.4'
}

About

dagger2 (2.13) with gradle example

Topics

Resources

Stars

20 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages