Comments (12)
Hi,
from scala-maven-plugin.
Many many thanks. That solved the issue I mentioned, but there is still one issue:
When I actually use Java 21's String templates, e.g. by running System.out.println(STR."=\{2+2}");
, I get the following error at the beginning of the compile step
invalid escape character
, which makes sense from the point of view of previous Java versions, but not Java 21. Moreover, java.lang.StringTemplate.STR
is correctly imported and I can freely use it as long I don't have \{
in my String which of course defeats the purpose of templates. Is there any solution for this one?
from scala-maven-plugin.
Please provide a reproducer as described here: https://stackoverflow.com/help/minimal-reproducible-example.
from scala-maven-plugin.
pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.aghasemi</groupId>
<artifactId>mvntest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.13.12</scala.version>
<scala.compat.version>2.13</scala.compat.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.scalatest/scalatest -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.compat.version}</artifactId>
<version>3.2.17</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scalatestplus/junit-4-13 -->
<dependency>
<groupId>org.scalatestplus</groupId>
<artifactId>junit-4-13_${scala.compat.version}</artifactId>
<version>3.2.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.8.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<javacArgs>--enable-preview</javacArgs>
<jvmArgs>
<jvmArg>--enable-preview</jvmArg>
</jvmArgs>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<enablePreview>true</enablePreview>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<!-- Tests will be run with scalatest-maven-plugin instead -->
<skipTests>true</skipTests>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>TestSuiteReport.txt</filereports>
<!-- Comma separated list of JUnit test class names to execute -->
<jUnitClasses>io.aghasemi.Tests</jUnitClasses>
<argLine>
--enable-preview
</argLine>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
and then io.aghasmi.Tests.java:
package io.aghasemi;
import static java.lang.StringTemplate.STR;
public class Tests {
public static void main(String[] args) {
System.out.println(STR."=\{2+2}");
return;
}
}
Temurin JDk 21 and Maven 3.9.4.
from scala-maven-plugin.
Could you please:
- trim down your pom.xml to what's really necessary
- push a maven project in a repo on GitHub
from scala-maven-plugin.
Could you please:
- trim down your pom.xml to what's really necessary
- push a maven project in a repo on GitHub
Here it is: https://github.com/aghasemi/mavan-scala-java21-test
Thanks
from scala-maven-plugin.
I have the exact same error with sbt.
It seems the Scala compiler doesn't support String templates yet (and I expect supporting an experimental Java feature to be very low priority).
Nothing we can do on our side. scala-maven-plugin will support automatically it once scalac supports it.
from scala-maven-plugin.
I see. Thanks. Quite a bit of a shame since the Scala compiler is actually OK with the preview features, except for this extension to escape characters it seems. Would not happen if \
was not chosen to use in templated strings :)
from scala-maven-plugin.
2 different things: being able to pass the javac option to enable features in preview and specifically being able to parse this new Java code. Might be related to the version of asm currently shipped.
Anyway, nothing we can do here. I recommend that you open an issue directly against Scala.
from scala-maven-plugin.
Thanks. I will. Just out of curiosity, why should the Scala compiler parse a Java source file?
from scala-maven-plugin.
So it can figure out the types and methods in Java code and compile the Scala code that might import them.
But it just parses Java sources, it doesn't compile them in bytecode, javac is used for that.
That's why you only need a JRE to compile Scala code, but you need a full JDK to compile mixed projects with Java code.
from scala-maven-plugin.
Of course! Many thanks.
from scala-maven-plugin.
Related Issues (20)
- compile scala and java project , Exception java.lang.StackOverflowError HOT 5
- deprecation warnings HOT 5
- Mixed Java & Scala 3.x compilation broke with release 4.7.2 and newer HOT 5
- Zinc is invoked with two -release arguments HOT 2
- bad option '-release' HOT 8
- Problems with java 17 and mvn build. HOT 4
- maven.compiler.release support is not consistent with javac
- Yet another (maybe user-error) problem with 4.8.1 HOT 1
- Java 11 is compatible with 2.11.12 onwards. But the referenced check is blocking this version HOT 1
- Why have this as 'unlicensed' when scala is apache 2 and this once was? HOT 2
- Maven Plugin Validation error? Depends on deprecated compatibility layer HOT 2
- Build error on `sun.*` APIs when `-release` Java version is lower than the execution Java version HOT 2
- Need to update to handle the movement of doxia to apache HOT 6
- Unused 'scalaCompatVersion' flag ? HOT 10
- scala-maven-plugin version for scala-library 2.12.15? HOT 2
- Race condition in sbt-compiler-bridge jar when running multimodule project with -T HOT 3
- Maven 3.9.4 Validation Warnings HOT 2
- Getting object scala in compiler mirror not found issue while running the application using jar HOT 3
- Trouble with installing the Maven plugin in IntelliJ HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-maven-plugin.