Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip if empty in Kotlin Maven plug-in

We have enabled the Kotlin Maven plug-in in our top-most project POM, like this:

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>${kotlin.version}</version>

    <executions>
        <execution>
            <id>compile</id>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>

        <execution>
            <id>test-compile</id>
            <phase>process-test-sources</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

ATM, only a handful of the modules in this project have Kotlin source code. (The project is around 50 modules.) The idea is that most will eventually have Kotlin code, and we don't want to have to wire things up on a per project basis. We want to configure it once, and forget about it.

This works except that we get this warning in the build for most modules:

[INFO] Kotlin Compiler version 1.0.2
[WARNING] No sources found skipping Kotlin compile

We had this problem with the JAR plug-in as well. That plug-in has a configuration option that allows us to do like this:

<configuration>
    <skipIfEmpty>true</skipIfEmpty>
</configuration>

This shutup that plug-in's similar warnings. The Kotlin compiler plug-in doesn't seem to have any such config option though.

So, my questions are:

  1. Is there such a configuration option that we're overlooking?
  2. Should we configure the Kotlin compiler plug-in differently to avoid this warning?

TIA!

like image 672
Travis Spencer Avatar asked May 15 '16 19:05

Travis Spencer


People also ask

What does Kotlin Maven plugin do?

The kotlin-maven-plugin compiles Kotlin sources and modules. Currently, only Maven v3 is supported.

Can you use Kotlin with Maven?

If you still prefer to stick with good old Maven, there is no problem. There is a plugin for it to support Kotlin as well. If you don't have Maven on your machine, you can follow the instructions at https://maven.apache.org/install.html to get it installed on your local machine.

Can Kotlin compile Java?

Yes. Kotlin is 100% interoperable with the Java programming language and major emphasis has been placed on making sure that your existing codebase can interact properly with Kotlin. You can easily call Kotlin code from Java and Java code from Kotlin. This makes adoption much easier and lower-risk.

What is mean by plugins in Maven?

Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM).


1 Answers

The default way to handle such things is to define the configuration like you have in the parent of the project via pluginManagement which prevents it's being inherited for all modules which is not correct. Than in those modules which are using Kotlin you need to add a few lines to the pom file:

<build>
  <plugins>
    <plugin>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

If the kotlin-maven-plugins contains such option i can't tell you cause i didn't find the source code of it nor does there exist a maven generated site which contains all the defaults and the options etc. which is not the case (Not really good)..

Or an other solution would be to change the kotlin-maven-plugin having it's own life cycle which means to change the code of the plugin...and just change the <packaging>kotlin</packaging> of those modules...which is work for the original authors to do...

If you have needed to add the option <skipIfEmpty>..</skipIfEmpty> for the maven-jar-plugin this sounds wrong as well...

like image 83
khmarbaise Avatar answered Sep 29 '22 08:09

khmarbaise