IntelliJ does not consider scala compiler options configured with maven

53 views Asked by At

How can i tell IntelliJ to use the compiler options configured in maven's net.alchim31.maven/scala-maven-plugin plugin settings in my pom.xml?

Goal

I have a Scala setup with Maven. I use IntelliJ Idea as IDE. My goal is to add integration tests with Testcontainers and Spring Boot which currently looks like this:

object IntegrationTest:
    private val database = new PostgreSQLContainer(DockerImageName.parse("postgres"))

    if DockerClientFactory.instance().isDockerAvailable then database.start()

    @DynamicPropertySource
    def databaseProperties(registry: DynamicPropertyRegistry): Unit =
        registry.add("spring.datasource.url", () => database.getJdbcUrl)
        registry.add("spring.datasource.username", () => database.getUsername)
        registry.add("spring.datasource.password", () => database.getPassword)

Problem

The scala compiler shows this error plus 5 similar errors:

scalac: possible data race involving globally reachable variable parameters in class JdbcDatabaseContainer: java.util.Map[String, String]
  use -Ylog:checkReentrant+ to find out more about why the variable is reachable.

Partial Fix

I was able to resolve it with a compiler option for test scope in my pom.xml:

<plugins>
  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>4.8.1</version>
    <executions>
      <execution>
        <id>scala-test-compile</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <args>
            <arg>-Ysafe-init</arg>    <!-- this one -->
          </args>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

Running mvn test in the console works just fine.

Remaining Problem

Executing any test or even the main application out of IntelliJ fails with the above error.

I also tried to add -Ysafe-init to Settings > Build, Execution, Deployment > Compiler > Scala Compiler > Additional compiler options, but without success.

0

There are 0 answers