在当前项目和插件组中找不到前缀'docker'的插件

时间:2017-11-15 07:15:49

标签: docker spring-boot maven-3 spring-cloud

使用Spring Cloud部署docker项目,pom.xml中的一些代码:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!-- tag::plugin[] -->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
        <!-- end::plugin[] -->
    </plugins>
</build>

当我执行命令mvn package docker:build时,它会引发上述错误:

    Downloaded: http://3.2.4.2:8888/repository/maven-public/org/apache/maven/plugins/maven-metadata.xml (14 KB at 5.7 KB/sec)
    Downloaded: http://3.2.4.2:8888/repository/maven-public/org/codehaus/mojo/maven-metadata.xml (21 KB at 7.3 KB/sec)
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] 
    [INFO] eureka-server ...................................... SUCCESS [ 26.279 s]
    [INFO] service-1 ......................................... SUCCESS [ 14.649 s]
    [INFO] demo1 ........................................... FAILURE [  2.850 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 45.535 s
    [INFO] Finished at: 2017-11-15T14:28:05+08:00
    [INFO] Final Memory: 47M/532M
    [INFO] ------------------------------------------------------------------------
    [ERROR] No plugin found for prefix 'docker' in the current project 
and in the plugin groups [org.sonatype.plugins, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/../Repository), nexus (http://3.2.4.2:8888/repository/maven-public/)]

如何解决?

3 个答案:

答案 0 :(得分:13)

将以下代码添加到您的专家conf/setting.xml

<pluginGroups>  
    <pluginGroup>com.spotify</pluginGroup>  
</pluginGroups>

如果您想获得更多详细信息,请参阅https://github.com/spotify/docker-maven-plugin/issues/322

答案 1 :(得分:4)

如果您正在使用dockerfile maven插件,则需要将docker:build更改为 dockerfile:build和docker:push到dockerfile:push

答案 2 :(得分:0)

对于我以不同的方式工作,如果你遵循maven插件模式{prefix}-maven-plugin ...在这种情况下是dockerfile-maven-plugin,你应该能够运行它:{{1} }。 我正在使用Maven:3,Spring Boot 2和Docker maven插件1.3.4