【问题标题】:How does Maven know where input files come from and where output files go during the generate-sources phase?在 generate-sources 阶段,Maven 如何知道输入文件来自哪里以及输出文件去哪里?
【发布时间】:2020-05-04 01:28:18
【问题描述】:

我是 Maven 新手。我有一个项目,其中包含一个由 SableCC 读取的语法定义文件,它是一个解析器生成器。 SableCC 读取一个语法文件并生成 Java 源代码,一旦编译,就会创建一个解析器。我的项目的其余部分使用解析器。

我不认为我的问题是 SableCC 问题,因为我已经看到类似的 POM.XML 文件使用 Antlr(另一个可与 SableCC 相媲美的解析器生成器),并且 POM.XML 的 <plugin> 部分看起来与我的 POM.XML 文件中的 <plugin> 部分几乎相同。

这是我项目的文件结构,标识了 SableCC 使用的那些部分:

这是我完整的 POM.XML 文件,我根据目前看到的插件示例(尤其是 SableCC 的示例)拼凑而成:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mbm</groupId>
    <artifactId>properties</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Properties</name>
    <description>Define and process program arguments</description>
    <dependencies>
    </dependencies>
    <build>
        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sablecc-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </pluginManagement>
    </build>
</project>

我的问题是 SableCC 插件如何知道输入文件在哪里以及生成的 4 类输出 Java 源文件(分析、词法分析器、节点和解析器)应该去哪里?我怀疑我需要在我的 POM 文件中添加更多 Maven“东西”,但我不知道是什么。

【问题讨论】:

    标签: maven maven-plugin sablecc


    【解决方案1】:

    您可以在此处查看插件配置: https://github.com/tychobrailleur/sablecc-maven-plugin

    更具体地说:

    sourceDirectory:包含语法文件的目录。默认情况下,${basedir}/src/main/sablecc

    outputDirectory:包含生成源的目录。默认情况下,${project.build.directory}/generated-sources/sablecc

    您还可以提取 JAR 并在 plugin.xml 文件中查看这些配置:

    <configuration>
      <outputDirectory implementation="java.lang.String">${project.build.directory}/generated-sources/sablecc</outputDirectory>
      <timestampDirectory implementation="java.lang.String">${basedir}/target</timestampDirectory>
      <sourceDirectory implementation="java.lang.String">${basedir}/src/main/sablecc</sourceDirectory>
      <project implementation="org.apache.maven.project.MavenProject">${project}</project>
      <staleMillis implementation="int" default-value="0">${lastModGranularityMs}</staleMillis>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-03
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      相关资源
      最近更新 更多