'kapt not working with maven and dagger in mixed kotlin/java project
Kapt doesnt work with maven, if we dont use kapt and just use the maven compiler for java it generates dagger code perfectly fine, but the problem is that java compiles after kotlin compiles and kotlin gives and error because it can't use dagger components before they are created, so the solution would be to use kapt. this is the plugin configuration
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<!-- Specify your annotation processors here. -->
<annotationProcessorPath>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.9</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.myanimelist/com.example.myanimelist.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and this is the error that gives
"C:\Program Files\BellSoft\LibericaJDK-17-Full\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList -Dmaven.home=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4 -Dclassworlds.conf=C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=63596:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds-2.6.0.jar;C:\Users\Roberto\.m2\wrapper\dists\apache-maven-3.8.4-bin\52ccbt68d252mdldqsfsn03jlf\apache-maven-3.8.4\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2022.1 compile
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.example:MyAnimeList >-----------------------
[INFO] Building MyAnimeList 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- kotlin-maven-plugin:1.6.21:kapt (kapt) @ MyAnimeList ---
[WARNING] 'tools.jar' was not found, kapt may work unreliably
[WARNING] C:\Users\Roberto\.m2\repository\org\checkerframework\checker-compat-qual\2.5.5\checker-compat-qual-2.5.5.jar: (-1, -1) The root is ignored because a module with the same name 'org.checkerframework.checker.qual' has been found earlier on the module path at: C:/Users/Roberto/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-base\17.0.1\javafx-base-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.base' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-controls\17.0.1\javafx-controls-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.controls' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-fxml\17.0.1\javafx-fxml-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.fxml' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[WARNING] C:\Users\Roberto\.m2\repository\org\openjfx\javafx-graphics\17.0.1\javafx-graphics-17.0.1-win.jar: (-1, -1) The root is ignored because a module with the same name 'javafx.graphics' has been found earlier on the module path at: C:/Program Files/BellSoft/LibericaJDK-17-Full
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
@Component(modules = {FiltersModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
@Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
@Component(modules = {RepositoriesModule.class})
^
symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
@Singleton
^
symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
@Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
@Data
^
symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
@Module(includes = RepositoriesModule.class)
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
@Module
^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt: (4, 46) Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt: (3, 46) Unresolved reference: DaggerControllersComponent
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.254 s
[INFO] Finished at: 2022-05-16T00:29:31+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.6.21:kapt (kapt) on project MyAnimeList: Compilation failure: Compilation failure:
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:12: error: cannot find symbol
[ERROR] @Component(modules = {FiltersModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\ControllersComponent.java:13: error: cannot find symbol
[ERROR] @Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:13: error: cannot find symbol
[ERROR] @Component(modules = {RepositoriesModule.class})
[ERROR] ^
[ERROR] symbol: class Component
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\components\RepositoriesComponent.java:14: error: cannot find symbol
[ERROR] @Singleton
[ERROR] ^
[ERROR] symbol: class Singleton
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\AnimeDTO.java:13: error: cannot find symbol
[ERROR] @Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\dto\BackupDTO.java:12: error: cannot find symbol
[ERROR] @Data
[ERROR] ^
[ERROR] symbol: class Data
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\FiltersModule.java:12: error: incompatible types: Module cannot be converted to Annotation
[ERROR] @Module(includes = RepositoriesModule.class)
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\java\com\example\myanimelist\di\modules\RepositoriesModule.java:17: error: incompatible types: Module cannot be converted to Annotation
[ERROR] @Module
[ERROR] ^
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\LoginController.kt:[4,46] Unresolved reference: DaggerControllersComponent
[ERROR] C:\Users\Roberto\IdeaProjects\ProyectoFinal1DAM\MyAnimeList\src\main\kotlin\com\example\myanimelist\controllers\inicio\RegisterController.kt:[3,46] Unresolved reference: DaggerControllersComponent
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Process finished with exit code 1
I have tried using older jdks versions but nothing changed
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
