无法使用 Yangtools 从 yang 文件生成 Pojos
Fail to generate Pojos from yang files using Yangtools
我正在尝试使用 OpenDaylight 根据此 guide 从 Yang 文件生成 Pojos。
我从 OpenDaylight github 克隆了 Yangtools 并使用 mvn clean install
构建了项目
我已将以下内容添加到我的 pom:
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
<version>2.0.8-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<!-- directory containing yang files to parse and generate code -->
<yangFilesRootDir>src/main/yang</yangFilesRootDir>
<codeGenerators>
<generator>
<codeGeneratorClass>
org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
</codeGeneratorClass>
<!-- directory into which generated files will be placed -->
<outputBaseDir>
target/generated-sources
</outputBaseDir>
</generator>
</codeGenerators>
<!-- if true, plugin will search for yang files also in dependent projects -->
<inspectDependencies>true</inspectDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>0.7.4-Lithium-SR4</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
但是我无法生成源代码。我收到以下错误:
[ERROR] Failed to execute goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources (default) on project odl-poc: Execution default of goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources failed: An API incompatibility was encountered while executing org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources: java.lang.AbstractMethodError: Method org/opendaylight/yangtools/maven/sal/api/gen/plugin/CodeGeneratorImpl.generateSources(Lorg/opendaylight/yangtools/yang/model/api/SchemaContext;Ljava/io/File;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/Collection; is abstract
我做错了什么?
看起来像版本不兼容 - 你引用的是 yang-maven-plugin 版本 2.0.8-SNAPSHOT,这是当前未发布的 master 分支,依赖 maven-sal-api-gen-plugin版本 0.7.4-Lithium-SR4,就像 5 个主要版本之前的版本一样,早已过时。
我正在尝试使用 OpenDaylight 根据此 guide 从 Yang 文件生成 Pojos。
我从 OpenDaylight github 克隆了 Yangtools 并使用 mvn clean install
我已将以下内容添加到我的 pom:
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
<version>2.0.8-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<!-- directory containing yang files to parse and generate code -->
<yangFilesRootDir>src/main/yang</yangFilesRootDir>
<codeGenerators>
<generator>
<codeGeneratorClass>
org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
</codeGeneratorClass>
<!-- directory into which generated files will be placed -->
<outputBaseDir>
target/generated-sources
</outputBaseDir>
</generator>
</codeGenerators>
<!-- if true, plugin will search for yang files also in dependent projects -->
<inspectDependencies>true</inspectDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>0.7.4-Lithium-SR4</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
但是我无法生成源代码。我收到以下错误:
[ERROR] Failed to execute goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources (default) on project odl-poc: Execution default of goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources failed: An API incompatibility was encountered while executing org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources: java.lang.AbstractMethodError: Method org/opendaylight/yangtools/maven/sal/api/gen/plugin/CodeGeneratorImpl.generateSources(Lorg/opendaylight/yangtools/yang/model/api/SchemaContext;Ljava/io/File;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/Collection; is abstract
我做错了什么?
看起来像版本不兼容 - 你引用的是 yang-maven-plugin 版本 2.0.8-SNAPSHOT,这是当前未发布的 master 分支,依赖 maven-sal-api-gen-plugin版本 0.7.4-Lithium-SR4,就像 5 个主要版本之前的版本一样,早已过时。