2017-04-25 44 views
0

我有一个项目与混合scala/java模块的标准多项目maven。Intellij不能很好的与多模块maven scala项目

当我在IntelliJ上打开此项目时,它无法将scala文件夹识别为sources/test-sources根文件夹。

. 
|-- pom.xml 
`-- src 
    |-- it 
    | |-- resources 
    | | `-- data.csv 
    | `-- scala #### TEST SOURCES ### 
    |  `-- com 
    |   `-- my 
    |    `-- example 
    |     `-- jetty 
    |      `-- JettyBasedServerIT.scala 
    |-- main 
    | `-- scala #### SOURCES ### 
    |  `-- com 
    |   `-- my 
    |    `-- example 
    |     `-- jetty 
    |      `-- JettyBasedServer.scala 
    `-- test 
     `-- scala #### TEST SOURCES ### 
      `-- com 
       `-- my 
        `-- example 
         `-- jetty 
          `-- MainArgumentsTest.scala 

因此,不能识别相互依赖关系。

我必须按模块去模块并手动设置源文件夹。

你知道如何自动完成吗?

回答

3

当我想用scala在intelliJ中设置maven子模块时,我遇到了类似的问题。我最终成功与特定的pom.xml。你可以这样调查。

只是为了信息我给你从我的pom.xml一些提取物,可能对你有用:

父pom.xml的

<pluginManagement> 
    <plugins> 
      <!-- configure scala style --> 
      <plugin> 
       <groupId>org.scalastyle</groupId> 
       <artifactId>scalastyle-maven-plugin</artifactId> 
       <version>0.8.0</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>check</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <verbose>false</verbose> 
        <failOnViolation>true</failOnViolation> 
        <includeTestSourceDirectory>true</includeTestSourceDirectory> 
        <failOnWarning>false</failOnWarning> 
        <sourceDirectory>${basedir}/src/main/scala</sourceDirectory> 
        <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory> 
        <outputFile>${project.basedir}/target/scalastyle-output.xml</outputFile> 
        <outputEncoding>UTF-8</outputEncoding> 
       </configuration> 
      </plugin> 

      <!-- set scala maven plugin version --> 
      <plugin> 
       <groupId>net.alchim31.maven</groupId> 
       <artifactId>scala-maven-plugin</artifactId> 
       <version>3.2.2</version> 
       <configuration> 
        <scalaCompatVersion>${scala.binary.version}</scalaCompatVersion> 
        <scalaVersion>${scala.version}</scalaVersion> 
       </configuration> 

      </plugin> 
    </plugins> 
</pluginManagement> 

儿童的pom.xml

<build> 
     <plugins> 

      <!-- Scala Compiler --> 
      <plugin> 
       <groupId>net.alchim31.maven</groupId> 
       <artifactId>scala-maven-plugin</artifactId> 
       <executions> 
        <!-- Run scala compiler in the process-resources phase, so that dependencies on 
         scala classes can be resolved later in the (Java) compile phase --> 
        <execution> 
         <id>scala-compile-first</id> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <jvmArgs> 
         <jvmArg>-Xms128m</jvmArg> 
         <jvmArg>-Xmx512m</jvmArg> 
        </jvmArgs> 
       </configuration> 
      </plugin> 

      <!-- Adding scala source directories to build path --> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>1.7</version> 
       <executions> 
        <!-- Add src/main/scala to eclipse build path --> 
        <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> 
        <!-- Add src/test/scala to eclipse build path --> 
        <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> 

      <!-- Scala Code Style, most of the configuration done via plugin management --> 
      <plugin> 
       <groupId>org.scalastyle</groupId> 
       <artifactId>scalastyle-maven-plugin</artifactId> 
       <configuration> 
        <configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation> 
       </configuration> 
      </plugin> 

不幸的是,我不能确切地说哪个部分是fondamental。希望它可以帮助。

1

奇怪的是,问题与maven进口商内存问题有关。 我增加了导入内存设置并重新导入了项目,它的工作方式就像魔术一样。 enter image description here

+0

你可以在你的pom.xml中设置这个选项,你可以在我的答案中看到。 – ImbaBalboa

+0

@ImbaBalboa感谢您的回答。我看到你配置了JVM参数,特别是我已经拥有并且不影响intellij的java-maven-plugin。 –