Maven阴影插件-无法执行目标

时间:2019-02-15 07:37:49

标签: java maven maven-plugin maven-shade-plugin

我一直在尝试重命名tika应用程序类。由于类路径上存在重复的类,因此存在加载冲突。当我尝试运行maven install -e时,抛出错误,我想使用

  

org.apache.tika

类别为

  

com.test1.tika

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

  <groupId>com.test1.tika</groupId>
  <artifactId>tika-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>tika-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-app</artifactId>
        <version>1.20</version>
    </dependency>
  </dependencies>


  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createSourcesJar>true</createSourcesJar>
                <relocations>
                    <relocation>
                        <pattern>org.apache.tika.</pattern>
                        <shadedPattern>com.test1.tika.</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

mvn软件包命令中的错误如下:

  

[错误]无法执行目标   org.apache.maven.plugins:maven-shade-plugin:2.3:shade(默认)   项目tika-app:创建阴影罐子时出错:null:   IllegalArgumentException-> [帮助1]   org.apache.maven.lifecycle.LifecycleExecutionException:失败   执行目标org.apache.maven.plugins:maven-shade-plugin:2.3:shade   (默认)项目tika-app:创建阴影罐子时出错:null       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:117)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:81)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build   (SingleThreadedBuilder.java:56)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:192)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch上增强   (Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode   (Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)上由以下原因引起:   org.apache.maven.plugin.MojoExecutionException:创建阴影时出错   jar:null       在org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:566)       在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:117)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:81)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build   (SingleThreadedBuilder.java:56)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:192)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch上增强   (Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode   (Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main上(Launcher.java:356)造成原因:java.lang.IllegalArgumentException       在org.objectweb.asm.ClassReader中。 (来源不明)       在org.objectweb.asm.ClassReader中。 (来源不明)       在org.objectweb.asm.ClassReader中。 (来源不明)       在org.apache.maven.plugins.shade.DefaultShader.addRemappedClass(DefaultShader.java:331)       在org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:165)       在org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:471)       在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:117)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject中   (LifecycleModuleBuilder.java:81)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build   (SingleThreadedBuilder.java:56)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:192)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch上增强   (Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode   (Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main上(Launcher.java:356)[ERROR] [ERROR]使用-X开关重新运行Maven   启用完整的调试日志记录。 [错误] [错误]有关更多信息   有关错误和可能的解决方案,请阅读以下内容   文章:[错误] [帮助1]   http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

1 个答案:

答案 0 :(得分:0)

将maven-compiler-plugin版本从2.3更改为3.2.1即可解决。