Search code examples
javamavendependency-injectiondagger-2java-11

Using Dagger with java 11 and maven


Does Google Dagger DIF works with java 11?

If not, what is the alternative, given that changing the project to use java 8 is not possible.


Solution

  • Yes, it is possible to use dagger 2.32 with maven and java 11.

    I was having issues with compilation process and eclipse environment.

    Eclipse was showing errors saying that DaggerMyClassComponent was not found. DaggerMyClassComponent is a generated class from MyClassComponent with @Component annotation from Dagger. This class (and others) is generated when we do 'mvn clean compile' command. Before that, eclipse will show errors.

    Also, if you run 'Maven -> Update Project', eclipse will fix the problem (it will run compile phase from maven). You can check generated classes in /target/generated-sources/annotation folder.

    Also, while developing with dagger and eclipse, errors may appear if you change classes annotated with @Components and @Modules. Running 'mvn clean' solves the errors related with generated classes from Dagger, because this command erases the /target folder content (including old generated classes from dagger).