将使用JavaCC的Maven Java项目移植到Scala

将使用JavaCC的Maven Java项目移植到Scala,scala,maven,maven-plugin,javacc,scala-java-interop,Scala,Maven,Maven Plugin,Javacc,Scala Java Interop,我正在尝试移植一个基于Maven的Java项目,该项目将JavaCC用于Scala。 我很高兴将JavaCC生成的类留在Java中,至少现在是这样。 但是,JavaCC生成的类取决于要转换的类 该项目可以从原始Java源代码构建,但是如果我用Scala源代码替换它们,Maven会首先尝试编译JavaCC生成的类,而看不到新代码提供的符号 接下来的问题似乎是如何让Maven首先生成Java代码,然后将Scala代码和生成的代码一起编译,这样编译器就可以找到所有依赖项。解决方案似乎是在pom.xml

我正在尝试移植一个基于Maven的Java项目,该项目将JavaCC用于Scala。 我很高兴将JavaCC生成的类留在Java中,至少现在是这样。 但是,JavaCC生成的类取决于要转换的类

该项目可以从原始Java源代码构建,但是如果我用Scala源代码替换它们,Maven会首先尝试编译JavaCC生成的类,而看不到新代码提供的符号

接下来的问题似乎是如何让Maven首先生成Java代码,然后将Scala代码和生成的代码一起编译,这样编译器就可以找到所有依赖项。解决方案似乎是在pom.xml中添加一些神奇的咒语。那应该是什么呢

我当前的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>bobj</groupId>
    <artifactId>bobj</artifactId>
    <version>0.9</version>
    <packaging>jar</packaging>

    <name>BOBJ algebraic specification and verification system</name>
    <url>http://github.com/fh-wedel/BOBJ</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <profiles>
        <profile>
            <id>scala-2.10</id>
            <properties>
                <scalaVersion>2.10.4</scalaVersion>
                <scalaBinaryVersion>2.10</scalaBinaryVersion>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-library</artifactId>
                    <version>${scalaVersion}</version>
                </dependency>
                <dependency>
                    <groupId>org.scala-lang</groupId>
                    <artifactId>scala-swing</artifactId>
                    <version>${scalaVersion}</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>bobj.BOBJ</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javacc-maven-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>javacc</id>
                        <goals>
                            <goal>javacc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.1.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <args>
                        <!-- work-around for https://issues.scala-lang.org/browse/SI-8358 -->
                        <arg>-nobootcp</arg>
                    </args>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/scala</source>
                                <source>src/main/javacc</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
这不是我写的。我从项目附带的pom.xml开始,添加了scala和build helper maven插件的部分
我从其他来源复制的。我的Maven fu是最小的,所以如果我做了一些被严重误导的事情,我不会感到惊讶。

事实证明我忘记了为

ie的scala maven插件需要

而不是通常的

            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>

你能把它们作为子项目吗?您可以通过该命令指定构建顺序。
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>