如何使用ODL Yangtools Maven插件为yang-version 1.1模块生成代码

问题描述 投票:0回答:1

如何使用OpenDaylight Yangtools maven插件从yang-version 1.1模块生成Java代码?

我有一个yang-version 1.1模型(接下来显示的第一部分)

module o-ran-sc-my-desc-v1 {
    yang-version 1.1;
    namespace "urn:o-ran:my-desc:1.0";
    prefix rxad;

    organization
        "O-RAN Software Community";
    contact
        "www.o-ran.org";

我从YANG工具指南https://wiki.opendaylight.org/view/YANG_Tools:User_Guide开始构造一个POM文件并生成代码。它具有旧版本tho和无效的代码生成器类名称。我升级到插件版本4.0.1,代码生成器版本3.0.9,两者都是Maven Central的最新版本,并弄清楚了代码生成器类的名称。终于在maven中工作了一些,但是现在我收到了此代码生成器错误:

[ERROR] Failed to execute goal org.opendaylight.yangtools:yang-maven-plugin:4.0.1:generate-sources (default) on project o1-netconf-client: 
Execution default of goal org.opendaylight.yangtools:yang-maven-plugin:4.0.1:generate-sources failed: An API incompatibility was 
encountered while executing org.opendaylight.yangtools:yang-maven-plugin:4.0.1:generate-sources: java.lang.NoSuchMethodError: 
org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils.getAllTypeDefinitions(Lorg/opendaylight/yangtools/yang/model/api/DataNodeContainer;)Ljava/util/Collection;

为了完整起见,下面发布了POM的相关部分。

            <plugin>
                <groupId>org.opendaylight.yangtools</groupId>
                <artifactId>yang-maven-plugin</artifactId>
                <version>4.0.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-sources</goal>
                        </goals>
                        <configuration>
                            <!-- directory containing yang files to parse and generate code -->
                            <yangFilesRootDir>my/agent/yang</yangFilesRootDir>
                            <codeGenerators>
                                <generator>
                                    <codeGeneratorClass>
                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
                                    </codeGeneratorClass>
                                    <!-- directory into which generated files will be placed -->
                                    <outputBaseDir>
                                        target/generated-sources/sal
                                    </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.mdsal</groupId>
                        <artifactId>maven-sal-api-gen-plugin</artifactId>
                        <version>3.0.9</version>
                        <type>jar</type>
                    </dependency>
               </dependencies>
            </plugin>

是否可能使用的版本不兼容?

opendaylight ietf-netmod-yang
1个回答
0
投票

[找到了使用Open Daylight从yang-version 1.1模型生成Java绑定类的解决方案:

  1. 将父pom设置为Open Daylight文件。父级指定兼容版本,定义代码生成器,等等。
  2. 将yang文件放在src / main / yang目录中。该目录的存在会从#1激活所需的配置文件。

正在工作的POM出现在下面,很短,希望这可以节省下一个人的挫败感。

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.opendaylight.mdsal</groupId>
        <artifactId>binding-parent</artifactId>
        <version>5.0.9</version>
        <relativePath></relativePath>
    </parent>
    <groupId>org.your.group.id.goes.here</groupId>
    <artifactId>o1-netconf-client</artifactId>
    <packaging>jar</packaging>
    <name>Descriptive Name Goes Here</name>
    <version>0.0.1-SNAPSHOT</version>
</project>

当我运行“ mvn install”时,执行的步骤包括生成源代码,测试,打包为jar等。这是关键的一个:

[INFO] --- yang-maven-plugin:4.0.6:generate-sources (binding) @ o1-netconf-client ---
[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
[INFO] yang-to-sources: Inspecting /Users/me/path/to/files/o1-netconf-client/src/main/yang
[INFO] yang-to-sources: Found 0 dependencies in 16.91 ms
[INFO] yang-to-sources: Project model files found: 2
[INFO] yang-to-sources: 2 YANG models processed in 174.2 ms
[INFO] yang-to-sources: Sources will be generated to /Users/me/path/to/files/o1-netconf-client/target/generated-sources/mdsal-binding
[INFO] Found 13 Binding types in 106.8 ms
[INFO] Generating 21 Binding source files into 8 directories
[INFO] yang-to-sources: Sources generated by org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl: 26 in 211.1 ms

© www.soinside.com 2019 - 2024. All rights reserved.