kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Cannot compile the project in multi-module Maven setup

Open Fossan opened this issue 1 year ago • 4 comments

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

Fossan avatar Sep 05 '24 08:09 Fossan

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

sandwwraith avatar Sep 23 '24 15:09 sandwwraith

Having the same issue, here is by environment:

  • Kotlin version: 2.0.20
  • Gradle version: 8.10.2
  • Kotlin Platforms: JVM
  • Java Version: 21.0.4 Oracle
  • IDE Version: IntelliJ IDEA 2024.2.3 (Ultimate Edition)

Details:

  • The @Suppress("PROVIDED_RUNTIME_TOO_LOW", "INLINE_CLASSES_NOT_SUPPORTED") workaround works for me
  • Fails the same way building within IntelliJ and with gradlew command line build:
$ ./gradlew build

> Task :compileKotlin FAILED
e: file:///Path/to/Example.kt:5:1 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.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 814ms
1 actionable task: 1 executed

jyennaco avatar Oct 07 '24 15:10 jyennaco

@jyennaco , do you have a small reproducer project? This error is difficult to reproduce locally without full build configuration.

shanshin avatar Mar 18 '25 19:03 shanshin

@jyennaco , do you have a small reproducer project? This error is difficult to reproduce locally without full build configuration.

I will set up a small public project for you to reproduce. Thank you!

jyennaco avatar Mar 19 '25 02:03 jyennaco