执行默认的spring-boot-maven-plugin重新打包失败

时间:2017-10-15 15:11:31

标签: java maven spring-boot

我有一个简单的project现在什么都不做,而且只是一个简单的Spring Boot 2应用程序,应该使用java 9

当我在mvnw clean package文件夹上运行hero-journey时,我收到此错误

ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M5:repackage (default) on project hero-journey-web: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M5:repackage failed.: RuntimeException ->
 [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M5:repackage (default) on project hero-journey-web: Execution default of goal org.springframework.boot:spring-boot-maven-plugin
:2.0.0.M5:repackage failed.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
        at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
        at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M5:repackage failed.
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 27 more
Caused by: java.lang.RuntimeException
        at org.springframework.asm.ClassVisitor.visitModule(ClassVisitor.java:148)
        at org.springframework.asm.ClassReader.readModule(ClassReader.java:762)
        at org.springframework.asm.ClassReader.accept(ClassReader.java:663)
        at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
        at org.springframework.boot.loader.tools.MainClassFinder.createClassDescriptor(MainClassFinder.java:267)
        at org.springframework.boot.loader.tools.MainClassFinder.doWithMainClasses(MainClassFinder.java:223)
        at org.springframework.boot.loader.tools.MainClassFinder.findSingleMainClass(MainClassFinder.java:203)
        at org.springframework.boot.loader.tools.Repackager.findMainMethod(Repackager.java:365)
        at org.springframework.boot.loader.tools.Repackager.findMainMethodWithTimeoutWarning(Repackager.java:354)
        at org.springframework.boot.loader.tools.Repackager.buildManifest(Repackager.java:325)
        at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:255)
        at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:248)
        at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:193)
        at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:221)
        at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:208)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 28 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :hero-journey-web

除了RuntimeException之外,它没有提供有关原因的任何特定信息,并且在类解析时发生了某些事情(似乎)。

mvn -version看起来像这样

Apache Maven 3.5.0
Maven home: L:\installed\apache-maven-3.5.0\bin\..
Java version: 9, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-9

有什么问题?

我的主pom.xml看起来像这样

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lapots.breed.hero.journey</groupId>
    <artifactId>hero-journey</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>hero-journey</name>
    <description>Start the journey towards the greatest powers</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.M5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <modules>
        <module>hero-journey-web</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>9</java.version>
    </properties>

    <distributionManagement>
        <repository>
            <id>google-drive-repository</id>
            <url>file://L:/google-drive/m2-artifactory/mvn-releases</url>
        </repository>
        <snapshotRepository>
            <id>google-drive-snapshot</id>
            <url>file://L:/google-drive/m2-artifactory/mvn-snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>google-drive-releases</id>
            <url>file://L:/google-drive/m2-artifactory/mvn-releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>google-drive-snapshots</id>
            <url>file://L:/google-drive/m2-artifactory/mvn-snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

我的子项目pom.xml看起来像这样

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.lapots.breed.hero.journey</groupId>
        <artifactId>hero-journey</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>hero-journey-web</artifactId>
    <description>Hero Journey - web application</description>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

3 个答案:

答案 0 :(得分:6)

我似乎遇到了现有的issue 所以我使用了@wilkinsona提供的解决方案来解决它。我在configuration添加了mainClass,项目已成功构建。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.lapots.breed.hero.journey.web.HeroJourneyWebApplication</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

答案 1 :(得分:0)

您可以使用这种方式。您将配置添加到pom,但是这种方式仅在编译器中有效。它在现实世界中不起作用。如果要使用.jar或.war。不起作用。 您必须在com文件中添加com.lapots.breed.hero.journey文件。然后,该文件始终有效

答案 2 :(得分:0)

我有类似的问题。

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for springboot-kafka 0.0.1-SNAPSHOT:
[INFO] 
[INFO] springboot-kafka ................................... SUCCESS [  1.016 s]
[INFO] springboot-kafka.model ............................. FAILURE [  1.862 s]
[INFO] springboot-kafka.producer .......................... SKIPPED
[INFO] springboot-kafka.consumer .......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.252 s
[INFO] Finished at: 2020-10-07T20:58:34+03:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage (repackage) on project springboot-kafka.model: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage failed: Unable to find main class -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage (repackage) on project springboot-kafka.model: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage failed: Unable to find main class
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage failed: Unable to find main class
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    ... 20 more
Caused by: java.lang.IllegalStateException: Unable to find main class
    at org.springframework.util.Assert.state(Assert.java:76)
    at org.springframework.boot.loader.tools.Packager.addMainAndStartAttributes(Packager.java:249)
    at org.springframework.boot.loader.tools.Packager.buildManifest(Packager.java:231)
    at org.springframework.boot.loader.tools.Packager.write(Packager.java:174)
    at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:135)
    at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:122)
    at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:175)
    at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:165)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    ... 21 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :springboot-kafka.model

我的主要pom.xml看起来像这样

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.example</groupId>
    <artifactId>springboot-kafka</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-kafka</name>
    <description>Demo project for Spring Boot</description>
    <packaging>pom</packaging>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>


    </dependencies>

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

    <modules>
        <module>springboot-kafka.producer</module>
        <module>springboot-kafka.consumer</module>
        <module>springboot-kafka.model</module>
    </modules>
</project>

我根据以下代码将<plugins>标记放入<pluginManagement>年龄,并且解决了我的问题。

 <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
</build>