maven 빌드의 첫 단계로 ANTLR4 문법을 컴파일하려면 어떻게해야합니까?빌드시 ANTLR4 문법 Java 파일을 자동으로 작성하도록 Maven 사용자 정의
수동으로 * .g4 파일에서 문법을 작성하는 것은 매우 간단합니다. 리눅스에서는 콘솔에서 java -jar /usr/local/lib/antlr-4.0-complete.jar grammarName.g4
을 실행하면됩니다. 이것은 빌드의 다음 단계에서 컴파일해야하는 일부 Java 파일을 작성합니다.
모든 * .g4 파일을 찾은 다음 위의 명령을 모두 실행하고 빌드를 계속 진행하도록 명령 할 수 있습니까? 문법 컴파일에 실패하면 빌드도 실패합니다.
아니면이 작업에 대처할 수있는 플러그인이 있습니까?
이미 this answer을 보았습니다. 단점은 IDE에 달려 있다는 것입니다. 나는 IDE와 시스템이 가능한 한 많이 독립적이기를 원한다. (Netbeans를 사용할 때 대답은 용납되지 않는다.) 내가 benzonico의 제안을 시도했습니다
편집 할 수 있습니다. 다른 답변에서 참조 된 pom.xml에 나열된대로 depenedcies를 추가했습니다. 여기 내 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>pl.kajman</groupId>
<artifactId>antlr-sandbox</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>antlr-sandbox</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.tunnelvisionlabs</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tunnelvisionlabs</groupId>
<artifactId>antlr4</artifactId>
<version>4.0</version>
<classifier>complete</classifier>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>bin</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>6</source>
<target>6</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments>
<Xlint />
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/antlr4</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.tunnelvisionlabs</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<sourceDirectory>src</sourceDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
자바 파일이 자동으로 폼 G4 파일을 생성하지만, 불행히도 많은 오류가있다. 그것들은 수동으로 컴파일 할 때 가지고있는 classpath와 매우 유사합니다. 오류 중 일부는 다음과 같습니다
/home/kajman/projects/antlr/antlr-sandbox/target/generated-sources/antlr4/main/java/pl/kajman/antlr/sandbox/grammars/ExprListener.java:[6,56] type org.antlr.v4.runtime.tree.ParseTreeListener does not take parameters
/home/kajman/projects/antlr/antlr-sandbox/target/generated-sources/antlr4/main/java/pl/kajman/antlr/sandbox/grammars/ExprParser.java:[44,32] cannot find symbol
symbol: method
getRuleContexts(java.lang.Class<main.java.pl.kajman.antlr.sandbox.grammars.ExprParser.StatContext>)
location: class main.java.pl.kajman.antlr.sandbox.grammars.ExprParser.ProgContext
제발 편집 좀하고 자세히 설명해 주시겠습니까? 당신의 대답은 분명히 해결책에 가까워졌습니다. 그러나 나는 아직 거기에 있지 않습니다. antlr4-런타임을 org.antlr antlr4 - 받는다는 - 플러그인' 4.0 com.tunnelvisionlabs - 그것은 지금 작동 –
kajman
, 나는 pom.xml 파일에서 종속성을 제거해야 4.0 –
kajman
문서 링크 프로 여기에 v4가 아닌 antlr v2가 있습니다. 최신 정보는 [antlr4-maven-plugin에 대한 도움말을 얻는 방법] (http://stackoverflow.com/q/15324837/2506021)을 참조하십시오. –