1

mixed compilation project of Scala and Java, and now upgrade jdk8->jdk21, use Java15+ feature text block

before:

String sql = "update hinsight.homeco_user_task set \n" +
        "file_path = ?,\n" +
        "err_msg = ?,\n" +
        "task_stop_time = current_timestamp(),\n" +
        "status = ?\n" +
        "where task_id = ?";

after:

String sql = """
    update hinsight.homeco_user_task
    set file_path = ?,
    err_msg = ?,
    task_stop_time = current_timestamp(),
    status = ?
    where task_id = ?""";

execute mvn clean compile

scala-maven-plugin cannot identify text block like """ and report unclosed string literal

[INFO] --- scala:4.8.0:compile (scala-compile-first) @ Discovery-M3-Operator-Java ---
[INFO] Compiler bridge file: C:\Users\z00624250\.sbt\1.0\zinc\org.scala-sbt\org.scala-sbt-compiler-bridge_2.12-1.8.0-bin_2.12.20__65.0-1.8.0_20221110T195421.jar
[INFO] compiling 32 Scala sources and 248 Java sources to D:\code\Discovery-M3-Operator-Java\target\classes ...
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/ModuleAnalysisOperator.java:26: unclosed string literal
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/ModuleAnalysisOperator.java:47: illegal character: 35
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/ModuleAnalysisOperator.java:55: unclosed string literal
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/ModuleAnalysisOperator.java:78: `;' expected but eof found.
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/UploadS3Operator.java:80: unclosed string literal
[ERROR] D:/code/Discovery-M3-Operator-Java/src/main/java/XXXX/UploadS3Operator.java:86: unclosed string literal
[ERROR] 6 errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.285 s
[INFO] Finished at: 2025-10-17T11:42:46+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.8.0:compile (scala-compile-first) on project Discovery-M3-Operator-Java: Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:4.8.0:compile failed: Compilation failed: InterfaceCompileFailed -> [Help 1]

Java and Scala exist cross dependencies and require mixed compile pom:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>${project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.14.1</version>
                <configuration>
                    <release>21</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.8.0</version>
                <configuration>
                    <scalaVersion>2.12.20</scalaVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <phase>
                            compile
                        </phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <systemPropertyVariables>
                        <maven.test.skip>true</maven.test.skip>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

How to ensure the use of Java15+ text block feature while compiling successfully?

4
  • 1
    if you are using jdk21 try using scala 3.x, also try upping the scala maven plugin to latest version 4.9.x Commented Oct 17 at 5:48
  • 2
    You probably need to confihure the -release:21 flag for the Scala compiler, to tell it to use Java 21. Commented Oct 17 at 13:25
  • <arg>-target:jvm-21</arg> or <arg>-release:21</arg> dont work @LuisMiguelMejíaSuárez Commented Oct 20 at 2:50
  • Project cannot accept major version upgrade 2.12.X->2.13.X@JorgeCampos Commented Oct 20 at 3:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.