I have a mixed Scala/Java project that doesn't compile well.
The problem arises when Java code is trying to call Scala code in the same package.
Of course, I have the standard layout:
I've looked at other similar Stackoverflow questions but this question is a little outdated. This other question doesn't help either.
I have also followed the scala-maven-plugin documentation page.
<build> <pluginManagement> <plugins> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.1.6</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <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> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <executions> <execution> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
I have tried unsuccessfully to follow this blog post.
IDEA project with Scala plugin imported from the pom.xml can compile and run my project successfully.
What is the right way of doing it? Does the Java code gets compiled twice? First by the Scala plugin and the by the Java plugin?.
If you're familiar with Maven, you can go ahead with the Scala Maven Plugin.
Maven Compiler Plugin might be the most important plugin in Maven. It is used to compile the sources of your project, which transform Java files ( *. java ) into class files ( *.
Create a new Scala Maven projectSelect New -> Project -> Other and then select Maven Project. On the next window, search for scala-archetype. Make sure you select the one in group net.
Here is a working example of pom.xml :
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>stackoverflow</groupId> <artifactId>q24448582</artifactId> <version>1.0-SNAPSHOT</version> <properties> <scala.version>2.10.3</scala.version> </properties> <dependencies> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>${scala.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <version>2.15.2</version> <executions> <execution> <id>compile</id> <goals> <goal>compile</goal> </goals> <phase>compile</phase> </execution> <execution> <id>test-compile</id> <goals> <goal>testCompile</goal> </goals> <phase>test-compile</phase> </execution> <execution> <phase>process-resources</phase> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With