标签: scala-maven-plugin

Maven:在一个项目中混合使用Java和Scala

今天我一直在努力找到一个合适的解决方案来设置一个包含Java和Scala代码的maven项目(它们之间有双向依赖关系).

我发现的解决方案通常包括在阶段调用scala-maven-plugin或maven-scala-plugin,process-resources以便它在默认的maven编译器插件之前运行(例如:http://www.hascode.com/2012/03 /片段-混合-斯卡拉的Java-IN-A-Maven的项目/,https://itellity.wordpress.com/2014/08/21/mixing-scala-and-java-in-a-maven-project/,官方scala-maven-plugin页面:http://davidb.github.io/scala-maven-plugin/example_java.html).

这导致了如下所示的解决方案:

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <recompileMode>incremental</recompileMode>
            <executions>
                <execution>
                    <id>scala-compile</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>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

这个解决方案运行良好 - 在process-resources阶段调用Scala编译,它编译Java和Scala代码,因此当maven编译器插件在compile阶段运行时,.class文件都已准备就绪.

问题是这个解决方案看起来并不干净.在编译阶段之前调用Scala编译过程只是为了确保它在maven编译器插件之前运行似乎是"hacky".

无论如何,Scala编译器编译Java类,所以我想我可以完全关闭默认的maven编译器插件,然后Scala编译器可以在这个compile阶段运行.虽然配置稍微长一些,但对我来说它看起来更干净:

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <recompileMode>incremental</recompileMode>
            <executions>
                <execution>
                    <id>scala-compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions> …
Run Code Online (Sandbox Code Playgroud)

java scala maven scala-maven-plugin

14
推荐指数
1
解决办法
8610
查看次数

如何为maven站点生成聚合scaladoc?

我有一个多模块Maven构建,我想在我的根模块中生成一个聚合的Scaladoc,类似于maven-javadoc-plugin的聚合目标.我的第一次尝试是:

<project ...>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <configuration>
                        <reportPlugins>
                            <plugin>
                                <artifactId>maven-project-info-reports-plugin</artifactId>
                            </plugin>
                            <plugin>
                                <groupId>net.alchim31.maven</groupId>
                                <artifactId>scala-maven-plugin</artifactId>
                                <reports>
                                    <report>doc</report>
                                </reports>
                                <configuration>
                                    <aggregateDirectOnly>false</aggregateDirectOnly>
                                    <sendJavaToScalac>false</sendJavaToScalac>
                                </configuration>
                            </plugin>
                            <plugin>
                                <artifactId>maven-javadoc-plugin</artifactId>
                                <reports>
                                    <report>aggregate</report>
                                </reports>
                            </plugin>
                        </reportPlugins>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

但是,aggregateDirectOnly属性似乎没有任何效果.我总是只为个别罐型POM获得Scaladoc.

我也尝试将forceAggregate设置为true,但它也没有效果.

这该怎么做?

scala maven maven-site-plugin scala-maven-plugin

13
推荐指数
1
解决办法
1732
查看次数

在Maven项目中启用宏天堂Scala编译器插件

我只是通过将scala-reflect.jar库作为pom中的依赖项包含普通scala-2.10宏在maven项目中工作,但是我需要打开宏天堂呢?我使用的是scala-2.10和scala-maven-plugin-3.1.5.

scala maven scala-2.10 scala-maven-plugin scala-macros

12
推荐指数
1
解决办法
3395
查看次数

pom配置强制使用scala maven插件使用jvm 7

由于scala 2.9.2项目与java 8版本之间不兼容,我需要在我的maven项目中手动指定jvm用法.

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>org.netlogo.extension</groupId>
    <packaging>jar</packaging>
    <artifactId>rungekuta</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${lib.org.scala-lang.scala.version}</version>
        </dependency>
        <dependency>
           <groupId>org.nlogo</groupId>
           <artifactId>netlogo</artifactId>
            <version>5.2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <properties>
        <lib.org.scala-lang.scala.version>2.9.3</lib.org.scala-lang.scala.version>
        <maven.scala.version>${lib.org.scala-lang.scala.version}</maven.scala.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Extension-Name>rungekuta</Extension-Name>
                            <Class-Manager>org.netlogo.extension.rungeKuta.RungeKutaExtension</Class-Manager>
                            <NetLogo-Extension-API-Version>5.0</NetLogo-Extension-API-Version>
                        </manifestEntries> …
Run Code Online (Sandbox Code Playgroud)

scala maven-plugin pom.xml maven scala-maven-plugin

10
推荐指数
1
解决办法
1871
查看次数

Maven不正当地启动fsc?

我正在尝试使用fsc(快速scala编译器)和我的maven项目.我pom.xml有:

...
 <execution>
   <id>cc</id>
   <goals>
     <goal>cc</goal>
   </goals>
   <phase>compile</phase>
   <configuration>
     <useFsc>true</useFsc>
     <once>true</once>
   </configuration>
 </execution>
...
Run Code Online (Sandbox Code Playgroud)

正如在使用maven编译Scala文件的最快方法中所讨论的那样

当我输入时mvn scala:cc,它会挂起:

[INFO] wait for files to compile...
Run Code Online (Sandbox Code Playgroud)

运行 mvn scala:cc -DdisplayCmd=true -Dverbose=true

 [INFO] cmd:  /bin/sh -c .../java -classpath [redacted] scala.tools.nsc.MainGenericRunner scala.tools.nsc.CompileServer >MainGenericRunner.out 2>MainGenericRunner.err
Run Code Online (Sandbox Code Playgroud)

这似乎很奇怪(不应该不包括scala.tools.nsc.MainGenericRunner?)我注意到MainGenericRunner.out包含

no such file: scala.tools.nsc.CompileServer
Run Code Online (Sandbox Code Playgroud)

这似乎证实了我的怀疑.

有没有人遇到这个,或者有解决方法?我真的很想用fsc来加速我的构建.我在Google群组中找到了一个具有类似输出的用户,但没有跟进.

在OSX上运行scala 2.8.1和maven 3.0.3

scala maven fsc scala-maven-plugin

8
推荐指数
1
解决办法
301
查看次数

Travis CI忽略了MAVEN_OPTS?

我的Scala项目(Maven管理的)未能在Travis上构建,GC overhead limit exceeded尽管在本地编译时仍然存在错误,但仍会出现错误MAVEN_OPTS=-Xmx3g -XX:MaxPermSize=512m.我怀疑Travis在某种程度上忽略了我MAVEN_OPTS:当我尝试测试Oracle JDK 8时,Travis记录:

$ Setting environment variables from .travis.yml
$ export MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"
Run Code Online (Sandbox Code Playgroud)

看起来不错.但是,它记录后不久:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0
Run Code Online (Sandbox Code Playgroud)

这是令人不安的,因为我-XX:MaxPermSize=192m只是在指定NOWHERE 512m.(这让我相信我-Xmx3g也被忽略了,导致编译失败.)

我尝试MAVEN_OPTS在我的pom中指定许多其他地方,但无济于事.例如,对于maven-scala-plugin,我有:

<configuration>
  ...
  <jvmArgs>
    <jvmArg>-Xmx3g</jvmArg>
    <jvmArg>-XX:MaxPermSize=512m</jvmArg>
  </jvmArgs>
</configuration>
Run Code Online (Sandbox Code Playgroud)

而且我在maven-surefire-plugin和scalatest插件下也有以下内容,尽管编译过程中构建失败而不是测试:

<configuration>
  <argLine>-Xmx3g -XX:MaxPermSize=512m</argLine>
</configuration>
Run Code Online (Sandbox Code Playgroud)

以下是我的.travis.yml的全部内容:

language: java
env:
  global:
    - MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx3g"
script: mvn clean install
jdk:
    - oraclejdk8
    - oraclejdk7
Run Code Online (Sandbox Code Playgroud)

我正在使用Scala 2.11.2和scala-maven-plugin 3.2.0.

scala maven travis-ci scala-maven-plugin

8
推荐指数
1
解决办法
1409
查看次数

如何使用scala-maven-plugin在scaladoc中记录私有元素?

我正在尝试使用scala-maven-plugin 3.0.2(Scala Version 2.9.2)为我的代码生成Scaladoc.我用的时候

mvn scala:doc
Run Code Online (Sandbox Code Playgroud)

然后我没有得到我的Scala代码的私有类型和元素的文档.我检查了插件文档,但我找不到一个选项.

奇怪的是,scaladoc插件确实为我的Java代码的私有元素生成了文档.但是因为它没有生成Java代码的HTML注释的文档,所以这是无用的.

我错过了什么吗?

java scala maven scala-maven-plugin

6
推荐指数
1
解决办法
338
查看次数

maven-shade-plugin 是否适用于 Scala 类?

我有一个包含 Java 和 Scala 组件的 maven 项目,但是当我使用 maven-shade-plugin 时,它会重新定位 Java 和 Scala 文件的包名,但只重命名 Java 文件中的包,Scala 文件仍然包含旧的包名,我错过了什么?

               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
               <version>3.2.1</version>
               <executions>
                   <execution>
                       <phase>package</phase>
                       <goals>
                           <goal>shade</goal>
                       </goals>
                       <configuration>
                           <!--<minimizeJar>true</minimizeJar>-->
                           <artifactSet>
                               <includes>
                                   <include>ml.dmlc:xgboost4j-spark</include>
                                   <include>ml.dmlc:xgboost4j</include>
                               </includes>
                           </artifactSet>
                           <filters>
                               <filter>
                                   <artifact>*:*</artifact>
                                   <excludes>
                                       <exclude>META-INF/*.SF</exclude>
                                       <exclude>META-INF/*.DSA</exclude>
                                       <exclude>META-INF/*.RSA</exclude>
                                   </excludes>
                               </filter>
                           </filters>
                           <relocations>
                               <relocation>
                                   <pattern>ml.dmlc.xgboost4j</pattern>
                                   <shadedPattern>ml.dmlc.xgboost4j.shaded</shadedPattern>
                               </relocation>
                           </relocations>
                           <transformers>
                           </transformers>
                       </configuration>
                   </execution>
               </executions>
           </plugin>```
Run Code Online (Sandbox Code Playgroud)

scala maven maven-shade-plugin scala-maven-plugin

6
推荐指数
1
解决办法
900
查看次数

maven中scaladoc的多模块聚合

我有一个包含5个模块的父项目.我试图弄清楚如何将模块级scaladoc聚合成一个有凝聚力的站点.任何帮助将非常感激.

scala maven-3 scaladoc scala-maven-plugin

5
推荐指数
1
解决办法
605
查看次数

编译scala时,maven"重新运行-feature"

我最近注意到scala编译器警告maven生成的内容如下所示:

[警告]警告:有4个弃用警告; 使用-deprecation重新运行以获取详细信息

[警告]警告:有3个功能警告; 重新运行-feature以获取详细信息

[警告]发现两个警告

我没有立即明白如何遵循警告的说明,因此我可以获得有关如何更改代码的详细信息.

compiler-warnings maven-3 scalac scala-maven-plugin

5
推荐指数
2
解决办法
6119
查看次数