GRPC-Protobuf报错Could not find artifact com.google.protobuf:protoc:exe:${os.detected.classifier}

GRPC-Protobuf报错Could not find artifact com.google.protobuf:protoc:exe:${os.detected.classifier}:3.12.0 in central解决方案

  • 问题背景
  • 解决方案
  • 总结
  • Lyric: 鲜嫩的 小时候

问题背景

在使用GRPC插件protobuf的时候,complie编译时出现以下错误:
Could not find artifact com.google.protobuf:protoc:exe:${os.detected.classifier}:3.12.0 in central (https://repo.maven.apache.org/maven2)

解决方案

1 在pom文件的build标签添加,少了这个排除就会出现这样的错误

<extensions>
    <extension>
        <groupId>kr.motd.mavengroupId>
        <artifactId>os-maven-pluginartifactId>
        <version>1.6.2version>
    extension>
extensions>

2 GRPC整个pom文件,不要少了依赖,全部使用这个应该是没有问题的


<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.0modelVersion>

    <groupId>a.b.cgroupId>
    <artifactId>grpc-demoartifactId>
    <version>1.0-SNAPSHOTversion>

    <properties>
        <java.version>1.8java.version>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <grpc.version>1.34.1grpc.version>
        <protobuf.version>3.12.0protobuf.version>
        <protoc.version>3.12.0protoc.version>
        <maven.compiler.source>1.8maven.compiler.source>
        <maven.compiler.target>1.8maven.compiler.target>
    properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.grpcgroupId>
                <artifactId>grpc-bomartifactId>
                <version>${grpc.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

    <dependencies>
        
        <dependency>
            <groupId>io.grpcgroupId>
            <artifactId>grpc-netty-shadedartifactId>
            <scope>runtimescope>
        dependency>
        <dependency>
            <groupId>io.grpcgroupId>
            <artifactId>grpc-protobufartifactId>
        dependency>
        <dependency>
            <groupId>io.grpcgroupId>
            <artifactId>grpc-stubartifactId>
        dependency>
        <dependency>
            <groupId>com.google.protobufgroupId>
            <artifactId>protobuf-java-utilartifactId>
            <version>${protobuf.version}version>
        dependency>
    dependencies>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.mavengroupId>
                <artifactId>os-maven-pluginartifactId>
                <version>1.6.2version>
            extension>
        extensions>

        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombokgroupId>
                            <artifactId>lombokartifactId>
                        exclude>
                    excludes>
                configuration>
            plugin>
            <plugin>
                
                <groupId>org.xolstice.maven.pluginsgroupId>
                <artifactId>protobuf-maven-pluginartifactId>
                <version>0.6.1version>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}protocArtifact>
                    <pluginId>grpc-javapluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}pluginArtifact>
                    
                    <protoSourceRoot>src/main/resources/protoprotoSourceRoot>
                    
                    <outputDirectory>${basedir}/src/main/javaoutputDirectory>
                    
                    <clearOutputDirectory>falseclearOutputDirectory>
                configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compilegoal>
                            <goal>compile-customgoal>
                        goals>
                    execution>
                executions>
            plugin>

            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.8.0version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
        plugins>
    build>

project>

总结

  • 依赖兼容是一个大问题,同样的jar包,但是版本号不同,里面的一些类和注解也有变化,导致不兼容




作为程序员第 33 篇文章,每次写一句歌词记录一下,看看人生有几首歌的时间,wahahaha …

Lyric: 鲜嫩的 小时候

你可能感兴趣的:(java异常错误问题,java,maven,intellij-idea)