Skip to content

Cannot compile the project in multi-module Maven setup #2808

Open
@Fossan

Description

@Fossan

Describe the bug
I have a multi-module Maven project, in which one of the shared modules is called commons and is used by other modules (let's called them A and B).
All modules (A, B and commons) contain classes that are @Serializable.
All modules do have kotlinx-serialization-json-jvm dependency.
The kotlin-maven-plugin is configured for all modules as follows:

  <plugin>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-maven-plugin</artifactId>
      <version>${kotlin.version}</version>
      <executions>
          <execution>
              <id>compile</id>
              <phase>compile</phase>
              <goals>
                  <goal>compile</goal>
              </goals>
          </execution>
      </executions>
      <configuration>
          <jvmTarget>21</jvmTarget>
          <compilerPlugins>
              <plugin>kotlinx-serialization</plugin>
          </compilerPlugins>
      </configuration>
      <dependencies>
          <dependency>
              <groupId>org.jetbrains.kotlin</groupId>
              <artifactId>kotlin-maven-serialization</artifactId>
              <version>${kotlin.version}</version>
          </dependency>
      </dependencies>
  </plugin>

When compiling the project, I'm getting an error on the first module that is using commons as dependency (e.g. A):

Your current kotlinx.serialization core version is 2.0.20, while current Kotlin compiler plugin unknown requires at least 1.0-M1-SNAPSHOT. Please update your kotlinx.serialization runtime dependency.

When I removed all @Serializable classes from commons and got rid of the plugin there, project was compiling again.
As a temporary workaround, I can suppress errors on all @Serializable classes which makes the compilation working:
@Suppress("PROVIDED_RUNTIME_TOO_LOW", "INLINE_CLASSES_NOT_SUPPORTED")
To Reproduce
In commons module:

@JvmInline
@Serializable
value class UserId(
    val id: String,
)

In A module:

import commons.UserId

@Serializable
data class Event(
    val userId: UserId,
)

Expected behavior
Multi-module Maven project can be compiled without any errors.

Environment

  • Kotlin version: 2.0.20
  • Library version: 1.7.2
  • Kotlin platforms: JVM
  • Maven version: 3.9.7
  • IDE version: IntelliJ IDEA 2024.2.1
  • Other relevant context: MacOS 14.5, JRE 21.0.4 Temurin

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions