I'm trying to use kapt in my project and it is working well when I compile manually using maven. How...
d
I'm trying to use kapt in my project and it is working well when I compile manually using maven. However, the Intellij IDEA integrated builder has trouble when compiling the generated sources. I've filed a bug to IDEA directly as I think the issue might be there (there's a simple reproducer project if anyone would be glad to look at it). To understand the issue more, I would like to know the reasoning behind and perhaps more details of this Maven/Kotlin guide that I followed. I noticed that when I don't "disable" the
maven-compiler-plugin
I get the same error during manual maven compilation ("package does not exist") as I get in IDEA when the pom is set up correctly. Can anyone shed more light into this issue?
a
Hi! Can you please look into project structure and check, that path to generated sources is correctly marked as
Source folders
d
Yes, both kapt and kaptKotlin (although the latter is empty) are marked.
a
Then you should go to this location and if there is no
com
folder, compiler will not find it - so you project tree should be like:
Copy code
.
└── target
    ├── generated-sources
    │   ├── kapt
    │   │   ├── com
    │   │   │   └── example
    │   │   │       └── blazedemo
    │   │   │           └── views
    │   │   │               ├── AnimalViewBuilder.java
    │   │   │               ├── ...
because
target/generated-sources/kapt
is source root, and it will be the starting point for the compiler to look for packages
d
Ah, I see. My dir structure looks little bit differently for the generated sources.
So I changed it in the pom, reimported the project, the Source Foulders are synced and the native build now works. Thanks!
Hmm, but now I have different problem: The manual compilation fails on
Copy code
[WARNING] Duplicate source root: /target/generated-sources/kapt/compile
I have this in the pom:
Copy code
<execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>src/main/kotlin</sourceDir>
                                <sourceDir>target/generated-sources/kapt/compile</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
a
I think it is more about https://youtrack.jetbrains.com/issue/KT-15040/Support-Kapt-in-IDEA-build-system-JPS, as IDK any documented way about how to make both Gradle and JPS builds with kapt live in one project and don’t affect each other, as JPS does not support Kapt. And as soon as you change your pom file, it will affect either Gradle build or import and further JPS build
BTW it is strange that warning fails the build
d
warning fails the build
I have it the compiler set to fail on warning.
The issue with Duplicate source root is NOT IDEA specific. It happens when running maven manually (
mvn compile
)
a
Can you share your pom?
d
Here's the updated pom from the KT issue
The sourceDir is changed to
target/generated-sources/kapt/compile
which satisfies IDEA but breaks
mvn compile
a
Looks like Kapt also added this source itself automatically
d
But if I remove the
sourceDir
then I would expect that the generated classes are compiled into the
classes
folder, which they are not...
It seems that I have to use the
add-sources
goal of the
build-helper-maven-plugin
. But then I don't understand why the source as added by kapt (as you say) doesn't get compiled...
1068 Views