Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.35k stars 619 forks source link

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

Open Fossan opened 3 weeks ago

Fossan commented 3 weeks ago

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

sandwwraith commented 5 days ago

Is the error reproducible when running mvn package or only in IDE?