Home > Mobile >  kotlin-bom for maven plugin
kotlin-bom for maven plugin

Time:04-04

I'm trying to use kotlin-bom to keep consistent versions for everything in my single-module maven project. I've got this in my pom.xml:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-bom</artifactId>
            <version>1.6.20</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Now I don't need to specify Kotlin version in any related dependency:

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
    </dependency>
    ...more dependencies...
</dependencies>

However, unfortunately, I still have to specify the Kotlin version for my plugins and their dependencies:

<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>1.6.20</version>
            <configuration>
                <compilerPlugins>
                    <plugin>kotlinx-serialization</plugin>
                </compilerPlugins>
                <jvmTarget>17</jvmTarget>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-serialization</artifactId>
                    <version>1.6.20</version>
                </dependency>
            </dependencies>
        </plugin>

Is there a way to get the kotlin-bom to work for plugins too?

CodePudding user response:

It is currently not possible to manage plugin versions by BOM, see this answer.

If it helps, you can define a property for kotlin version

<properties>
    <kotlin.version>1.6.20</kotlin.version>
</properties>

and use this property as bom version and plugin (and its dependencies) version, so that you'll have the same version everywhere at least:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-bom</artifactId>
            <version>${kotlin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <configuration>
                <compilerPlugins>
                    <plugin>kotlinx-serialization</plugin>
                </compilerPlugins>
                <jvmTarget>17</jvmTarget>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-serialization</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
  • Related