简体   繁体   English

Maven 在生成源阶段如何知道输入文件来自哪里以及 output 文件 go 来自哪里?

[英]How does Maven know where input files come from and where output files go during the generate-sources phase?

I am new to Maven.我是 Maven 的新手。 I have a project which includes a grammar definition file that is read by SableCC, which is a parser generator.我有一个项目,其中包含一个由 SableCC 读取的语法定义文件,它是一个解析器生成器。 SableCC reads a grammar file and generates Java source code that, once compiled, creates a parser. SableCC 读取一个语法文件并生成 Java 源代码,一旦编译,就会创建一个解析器。 The parser is used by the rest of my project.该解析器由我项目的 rest 使用。

I don't think my question is a SableCC question, as I've seen similar POM.XML files that use Antlr (another parser generator that is comparable to SableCC) and the <plugin> section of that POM.XML looks nearly the same as my <plugin> section in my POM.XML file.我不认为我的问题是 SableCC 问题,因为我看到类似的 POM.XML 文件使用 Antlr(另一个与 SableCC 相当的解析器生成器),并且该 POM.XML 的<plugin>部分看起来几乎相同作为我的 POM.XML 文件中的<plugin>部分。

Here is my project's file structure, identifying those parts that are used by SableCC:这是我项目的文件结构,标识了 SableCC 使用的那些部分:

在此处输入图像描述

Here is my complete POM.XML file, which I've cobbled together based on the plugin examples I've seen so far (and in particular, the one for 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>

My question is how does the SableCC plugin know where the input file is and where the 4 categories of generated output Java source files (analysis, lexer, node and parser) should go?我的问题是 SableCC 插件如何知道输入文件在哪里以及生成的 4 类 output Java 源文件(分析、词法分析器、节点和解析器)应该在哪里 Z34D1F91FB2E514B8576ZFAB1 I suspect I need to add more Maven "stuff" to my POM file, but I don't know what.我怀疑我需要在我的 POM 文件中添加更多 Maven “东西”,但我不知道是什么。

You can see the plugin configurations here: https://github.com/tychobrailleur/sablecc-maven-plugin您可以在此处查看插件配置: https://github.com/tychobrailleur/sablecc-maven-plugin

More specifically:进一步来说:

sourceDirectory: Directory containing grammar files. sourceDirectory:包含语法文件的目录。 By default, ${basedir}/src/main/sablecc默认情况下,${basedir}/src/main/sablecc

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

You can also extract the JAR and see these configurations in the plugin.xml file:您还可以提取 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM