java - Scala、Maven 和 Java 集成的构建失败

标签 java scala maven jenkins

我实际上正在为 Jenkins 开发一个插件,我想在我的插件中集成 Scala、Java 和 Maven。我用 Java 开发了部分插件,我想用 Scala 开发其他部分。 问题是当我集成所有这些(maven、Scala 和 Java)时,我从 scala maven 插件中得到这个错误:

    [INFO] artifact org.kohsuke.stapler:stapler: checking for updates from scala
[INFO] D:\workspace\remote-deployment-new\src\main\java:-1: info: compiling
[INFO] D:\workspace\remote-deployment-new\target\generated-sources\localizer:-1: info: compiling
[INFO] Compiling 4 source files to D:\workspace\remote-deployment-new\target\classes at 1352200897840
[ERROR] D:\workspace\remote-deployment-new\src\main\java\com\ebiznext\plugins\RemoteDeployment.java:33: error: RemoteDep
loyment is already defined as package RemoteDeployment
[INFO] public class RemoteDeployment extends Plugin implements Action, ExtensionPoint, Describable<RemoteDeployment> {
[INFO]              ^
[ERROR] one error found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.801s
[INFO] Finished at: Tue Nov 06 12:21:39 CET 2012
[INFO] Final Memory: 27M/370M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.1.0:compile (default) on project remote-deploymen
t-new: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1(Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我完全理解类 RemoteDeployment 已定义为包的错误。这是真的,因为在为 Jenkins 开发插件时,如果我有一个类,例如 RemoteDeployment 定义在包 com.ebiznext.plugins 中,我必须创建一个包 com.ebiznext。 src/main/resources 下的 plugins.RemoteDeployment。那是 Jenkins 的约定,我对此无能为力。

我该如何解决这个问题?

这是我的 POM:

<project>

<parent>
    <groupId>org.jenkins-ci.plugins</groupId>
    <artifactId>plugin</artifactId>
    <version>1.466</version><!-- which version of Jenkins is this plugin built 
        against? -->
</parent>
<groupId>com.ebiznext.plugins</groupId>
<artifactId>remote-deployment-new</artifactId>
<version>1.0</version>
<name>Remote Deployment</name>
<packaging>hpi</packaging>
    ....         
    <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.1.0</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>

最佳答案

我建议使用 net.alchim31.maven:scala-maven-plugin 进行编译。然后,您可以将参数设置为编译器 -Yresolve-term-conflict:object

例如:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <configuration>
        <recompileMode>incremental</recompileMode>   <!-- NOTE: incremental compilation although faster requires passing to MAVEN_OPTS="-XX:MaxPermSize=128m" -->
        <useZincServer>true</useZincServer>          <!-- NOTE: if you have Zinc server installed and running, you can get faster compilation by enabling this -->
        <!-- addScalacArgs>-feature</addScalacArgs -->
        <args>
            <arg>-Yresolve-term-conflict:object</arg>   <!-- required for package/object name conflict in Jenkins jar -->
        </args>
        <javacArgs>
            <javacArg>-Xlint:unchecked</javacArg>
            <javacArg>-Xlint:deprecation</javacArg>
        </javacArgs>
    </configuration>
    <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>

有关示例,请参见此处:https://github.com/adamretter/jenkins-scala-plugin/blob/master/jenkins-scala-plugin-executer/pom.xml#L57

关于java - Scala、Maven 和 Java 集成的构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13250248/

相关文章:

java - EJB 依赖于另一个 EJB?

scala - akka.io 在 2.3 中逐行接收

scala - Scala中的协方差逆变错误

java - 有没有办法用唯一的配置文件编译类并以其他方式排除它?

maven - 使用自定义 Checkstyle 运行 Maven Checkstyle

maven - 将 maven-shade-plugin 与 maven-assembly-plugin 一起使用

java - 如何从 Android 客户端进行经过身份验证的 django Rest api 调用?

java - 如何从Java中的另一个类获取列表值

java - Cassandra 性能相对于两个应用程序主机是不同的

sql - 列模式的 Spark SQL 区分大小写过滤器