【问题标题】:Error while adding protobuf dependency to maven将 protobuf 依赖项添加到 maven 时出错
【发布时间】:2013-05-16 03:03:41
【问题描述】:

我正在尝试将 protobuf 依赖项添加到我的 maven 项目中。 我已经使用安装了 protobuf jar 文件 mvn install:install-file -Dpackaging=jar\ -DgeneratePom=true\
-DgroupId=com.google.protobuf\ -DartifactId=protobuf-java\ -Dfile=protobuf-java-2.5.0.jar\ -Dversion=2.5.0

Mypom.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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProtobufExample</groupId>
<artifactId>ProtobufTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProtobufTest</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <skip.tests>false</skip.tests>
</properties>


<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.4.1</version>
            <scope>compile</scope>
        </dependency>

</dependencies>
<build>
    <finalName>ProtobufTest</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <finalName>${project.name}-${project.version}</finalName>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <finalName>${project.name}-${project.version}</finalName>
                <descriptors>
                    <descriptor>src/assembly/dist.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <phase>generate-sources</phase>
                    <configuration>
                        <protoSourceRoot>${basedir}/src/main/proto/</protoSourceRoot>
                        <includes>
                            <param>**/*.proto</param>
                        </includes>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <protocExecutable>/usr/local/bin/protoc</protocExecutable>
            </configuration>
        </plugin>

    </plugins>

</build>

当我尝试使用“mvn test”对其进行测试时,我收到以下错误: 无法解析 com.google.protobuf:protobuf-java:2.5.0 的插件描述符 在 META-INF/maven/plugin.xml 中找不到插件描述符

请帮我弄清楚我哪里出错了。

【问题讨论】:

    标签: maven protocol-buffers


    【解决方案1】:

    根据你的pom文件的如下sn-p定位问题:

      <plugin>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>2.5.0</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <goals>
                    <goal>test</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                    <protoSourceRoot>${basedir}/
    

    问题在于 protobuf-java 不是 插件。所以这不可能工作。

    【讨论】:

    • 感谢您的回复。是的,错误出在我的 pom 文件的上述 sn-p 上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 2011-06-25
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多