Maven only selects src / main / java or src / main / scala as the source folder, never

I am using Eclipse 3.7 w / m2e (installed 2 weeks ago), with Java 6 and Scala 2.10.

When I use m2e to update the project configuration, depending on how I configured my .pom, it always selects src/main/java && src/test/java or it selects src/main/scala && src/test/scala in as source folders. I would like all four to be source folders.

Here is my .pom

 <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>me.my.name</groupId> <artifactId>ai.chess</artifactId> <version>0.0.1-SNAPSHOT</version> <name>chessAI</name> <description>Chess AI</description> <repositories> <repository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> </dependencies> <build> <!-- <sourceDirectory>src/main/scala</sourceDirectory> <testSourceDirectory>src/test/scala</testSourceDirectory> --> <plugins> <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> <configuration> <jvmArgs> <jvmArg>-Xms64m</jvmArg> <jvmArg>-Xmx1024m</jvmArg> </jvmArgs> <sources> <source>src/main/scala</source> <source>src/main/java</source> <source>src/test/scala</source> <source>src/test/java</source> </sources> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <!--This plugin configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId> org.scala-tools </groupId> <artifactId> maven-scala-plugin </artifactId> <versionRange> [2.15.2,) </versionRange> <goals> <goal>compile</goal> </goals> </pluginExecutionFilter> <action> <ignore></ignore> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> </build> 

In the end, I would like to create UberJar with all the necessary dependencies so that it can run on a server that does not support Scala (but does Java). The basis for playing chess is given in Java, so I would like to use it with Scala

I can just go back to using Ant for the build if Maven still hurts.

PS With this .pom, it uses java source folders

+7
source share
3 answers

scala -maven-plugin ( formerly called maven-scala-plugin ) requires some additional configuration to run mixed Scala / Java projects , but if you follow their instructions (copied below), it should add all the necessary directories to your build path.

 <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> 
+6
source

You have two options: the first is to split the project in the parent project with two modules, each of which has its own pom. This is a more natural way to do this with maven, but since I am not a scala user, I am not completely sure of the possibilities of your installation.

  <parent> ai.chess (packaging: pom) <module> ai.chess.java (packaging: jar) <module> au.chess.scala (using <sourceDirectory>) 

The second option is to save the layout as is and use build-helper-maven-plugin to add the source directories to the assembly; eg:

 <project> ... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/scala</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/scala</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> 
+4
source
  • upgrade to scala -maven-plugin (scala -tools.org no longer exists since 2 years)
  • use an additional target source (do the same as build-helper-maven-plugin for scala only)

You can also store .java and .scala files in the same src / main / xxx and src / test / xxx files, the java compiler ignores * .scala and the scala compiler, which is used as.

0
source

All Articles