当使用 jib 命令 mvn clean 编译 jib:build 构建我的服务项目时,它给出以下错误:
未能执行目标 com.google.cloud.tools:jib-maven-plugin:1.0.2:build (构建映像和标记映像(在项目 my-service 上:多个有效 找到主类:com.myservice.MyServiceApplication, io.swagger.Swagger2SpringBoot,也许你应该添加一个
mainClass
配置到抖动插件 -> [帮助 1]
但是我已经为弹簧引导设置了主类
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
它仍然不起作用。
我尝试将其添加到动臂配置中以:
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</container>
</configuration>
<executions>
<execution>
<id>build-image-and-tag-image</id>
<phase>package</phase>
<goals>
<goal>dockerBuild</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
它仍然不起作用。任何其他强制 jib 忽略其他类并使用 com.myservice.MyServiceApplication 的方法。
注意:mvn全新安装工作正常,我使用它有一个独立的弹簧启动应用程序没有问题。
主类需要在 pom.xml 文件的构建><>定义<插件中设置。>
解决问题看起来像这样:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.myservice.MyServiceApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.myservice.MyServiceApplication</mainClass>
<ports>
<port>8080</port>
</ports>
<environment>
<application.title>${project.name}</application.title>
<application.version>${project.version}</application.version>
</environment>
<jvmFlags>
<jvmFlag>-javaagent:/usr/local/newrelic/newrelic.jar</jvmFlag>
</jvmFlags>
</container>
</configuration>
</plugin>
.... (more plugin)
</plugins>
</build>