在生成源代码阶段,Maven 如何知道输入文件来自哪里以及输出文件去了哪里?
How does Maven know where input files come from and where output files go during the generate-sources phase?
我是 Maven 新手。我有一个项目,其中包含一个由 SableCC 读取的语法定义文件,它是一个解析器生成器。 SableCC 读取一个语法文件并生成 Java 源代码,一旦编译,就会创建一个解析器。我的项目的其余部分使用解析器。
我不认为我的问题是 SableCC 问题,因为我已经看到类似的 POM.XML 文件使用 Antlr(另一个与 SableCC 相当的解析器生成器)和 <plugin>
部分其中 POM.XML 看起来与我 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 插件如何知道输入文件在哪里以及生成的输出 Java 的 4 类源文件(分析、词法分析器、节点和解析器)应该放在哪里?我怀疑我需要在我的 POM 文件中添加更多 Maven "stuff",但我不知道是什么。
您可以在这里查看插件配置:
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>
我是 Maven 新手。我有一个项目,其中包含一个由 SableCC 读取的语法定义文件,它是一个解析器生成器。 SableCC 读取一个语法文件并生成 Java 源代码,一旦编译,就会创建一个解析器。我的项目的其余部分使用解析器。
我不认为我的问题是 SableCC 问题,因为我已经看到类似的 POM.XML 文件使用 Antlr(另一个与 SableCC 相当的解析器生成器)和 <plugin>
部分其中 POM.XML 看起来与我 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 插件如何知道输入文件在哪里以及生成的输出 Java 的 4 类源文件(分析、词法分析器、节点和解析器)应该放在哪里?我怀疑我需要在我的 POM 文件中添加更多 Maven "stuff",但我不知道是什么。
您可以在这里查看插件配置: 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>