-
Notifications
You must be signed in to change notification settings - Fork 4.2k
update: update Compile Kotlin and Java sources in Maven #4785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0772b71
to
ec066ba
Compare
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
ec066ba
to
b2c8aae
Compare
I would suggest additionally highlighting that in the setup Kotlin + Java, we need to let Kotlin compiler know about the Java sources, so that's why we configure |
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<extensions>true</extensions> <!-- You can set this option | ||
to automatically take information about lifecycles --> | ||
<extensions>true</extensions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that actually this <extensions>true</extensions>
does not make any sense. According to the previous comments, it could help avoid some configuration, but that does not appear to be true in Kotlin + Java in this particular configuration.
However, if we modify the example to
<plugins>
<!-- Kotlin compiler plugin -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>default-test-compile</id>
<phase>test-compile</phase>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
we can completely skip the Java plugin configuration and it would just work, thanks to the <extensions>
setup. This configuration indeed seems much easier and shows benefit of extensions
Note that I changed execution IDs in this example.
I would suggest introducing something similar to how we show Kotlin/Groovy scripts, aka "tabs" for showing configuration with <extensions>true</extensions>
and without it.
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<extensions>true</extensions> <!-- You can set this option | ||
to automatically take information about lifecycles --> | ||
<extensions>true</extensions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, interesting, I tried just copy-pasting the setup (both before any changes and from this PR) on top of pure Kotlin setup – it leads to incorrect configuration when Java code can see Kotlin code, but Kotlin code cannot see Java.
Either removing the extensions setup or removing of the following configuration helps.
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
With the abovementioned change of execution id, it works fine. That's because setup from extensions creates executions default-compile
and default-test-compile
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
b2c8aae
to
acb9cf7
Compare
No description provided.