java – 无法用maven遮住jar(INVOKESPECIAL / STATIC)

前端之家收集整理的这篇文章主要介绍了java – 无法用maven遮住jar(INVOKESPECIAL / STATIC)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
完整的错误消息:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project –: Error creating shaded jar: INVOKESPECIAL/STATIC on interfaces require ASM 5 -> [Help 1]

我试图阴影的jar文件位于my own remote repository,使用sonatype nexus.这是我的pom配置:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.codelanx</groupId>
  5. <artifactId>phanaticprison</artifactId>
  6. <version>1.0.0</version>
  7. <name>PhanaticPrison</name>
  8. <packaging>jar</packaging>
  9.  
  10. <repositories>
  11. <repository>
  12. <id>bukkit-repo</id>
  13. <url>http://repo.bukkit.org/content/repositories/public/</url>
  14. </repository>
  15. <repository>
  16. <id>codelanx-repo</id>
  17. <url>http://repo.codelanx.com/content/repositories/public/</url>
  18. </repository>
  19. </repositories>
  20. <licenses>
  21. <license>
  22. <name>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</name>
  23. <url>https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode</url>
  24. <distribution>repo</distribution>
  25. </license>
  26. </licenses>
  27.  
  28. <build>
  29. <plugins>
  30. <plugin>
  31. <groupId>org.apache.maven.plugins</groupId>
  32. <artifactId>maven-shade-plugin</artifactId>
  33. <version>2.3</version>
  34. <configuration>
  35. <artifactSet>
  36. <includes>
  37. <include>com.codelanx:codelanxlib</include>
  38. </includes>
  39. </artifactSet>
  40. <minimizeJar>true</minimizeJar>
  41. </configuration>
  42. <executions>
  43. <execution>
  44. <phase>package</phase>
  45. <goals>
  46. <goal>shade</goal>
  47. </goals>
  48. </execution>
  49. </executions>
  50. </plugin>
  51. </plugins>
  52. <resources>
  53. <resource>
  54. <targetPath>.</targetPath>
  55. <directory>${basedir}/src/main/resources</directory>
  56. <filtering>true</filtering>
  57. </resource>
  58. </resources>
  59. <finalName>${project.name}</finalName>
  60. </build>
  61.  
  62. <dependencies>
  63. <dependency>
  64. <groupId>org.bukkit</groupId>
  65. <artifactId>bukkit</artifactId>
  66. <version>LATEST</version>
  67. <type>jar</type>
  68. </dependency>
  69. <dependency>
  70. <groupId>com.codelanx</groupId>
  71. <artifactId>codelanxlib</artifactId>
  72. <version>LATEST</version>
  73. <type>jar</type>
  74. </dependency>
  75. </dependencies>
  76.  
  77. <properties>
  78. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  79. <maven.compiler.source>1.8</maven.compiler.source>
  80. <maven.compiler.target>1.8</maven.compiler.target>
  81. </properties>
  82. </project>

谷歌搜索错误导致很少的结果,我收集的信息的主要部分是Java 8’s static interface methods could cause this,但我还没有找到更多. jar文件我试图遮蔽does indeed have one of these static methods,但即使我仍然必须能够使用它们并遮住罐子?我不确定错误意味着要求“ASM 5”(汇编?),所以任何方向都会受到赞赏.

我有效的pom(mvn help:effective-pom):

  1. <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">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.phanaticmc</groupId>
  4. <artifactId>phanaticprison</artifactId>
  5. <version>1.0.0</version>
  6. <name>PhanaticPrison</name>
  7. <licenses>
  8. <license>
  9. <name>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International</name>
  10. <url>https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode</url>
  11. <distribution>repo</distribution>
  12. </license>
  13. </licenses>
  14. <properties>
  15. <maven.compiler.source>1.8</maven.compiler.source>
  16. <maven.compiler.target>1.8</maven.compiler.target>
  17. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.bukkit</groupId>
  22. <artifactId>bukkit</artifactId>
  23. <version>LATEST</version>
  24. <scope>compile</scope>
  25. </dependency>
  26. <dependency>
  27. <groupId>com.codelanx</groupId>
  28. <artifactId>codelanxlib</artifactId>
  29. <version>LATEST</version>
  30. <scope>compile</scope>
  31. </dependency>
  32. </dependencies>
  33. <repositories>
  34. <repository>
  35. <id>bukkit-repo</id>
  36. <url>http://repo.bukkit.org/content/repositories/public/</url>
  37. </repository>
  38. <repository>
  39. <id>codelanx-repo</id>
  40. <url>http://repo.codelanx.com/content/repositories/public/</url>
  41. </repository>
  42. <repository>
  43. <snapshots>
  44. <enabled>false</enabled>
  45. </snapshots>
  46. <id>central</id>
  47. <name>Central Repository</name>
  48. <url>http://repo.maven.apache.org/maven2</url>
  49. </repository>
  50. </repositories>
  51. <pluginRepositories>
  52. <pluginRepository>
  53. <releases>
  54. <updatePolicy>never</updatePolicy>
  55. </releases>
  56. <snapshots>
  57. <enabled>false</enabled>
  58. </snapshots>
  59. <id>central</id>
  60. <name>Central Repository</name>
  61. <url>http://repo.maven.apache.org/maven2</url>
  62. </pluginRepository>
  63. </pluginRepositories>
  64. <build>
  65. <sourceDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\src\main\java</sourceDirectory>
  66. <scriptSourceDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\src\main\scripts</scriptSourceDirectory>
  67. <testSourceDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\src\test\java</testSourceDirectory>
  68. <outputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\classes</outputDirectory>
  69. <testOutputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\test-classes</testOutputDirectory>
  70. <resources>
  71. <resource>
  72. <targetPath>.</targetPath>
  73. <filtering>true</filtering>
  74. <directory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\src\main\resources</directory>
  75. </resource>
  76. </resources>
  77. <testResources>
  78. <testResource>
  79. <directory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\src\test\resources</directory>
  80. </testResource>
  81. </testResources>
  82. <directory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target</directory>
  83. <finalName>PhanaticPrison</finalName>
  84. <pluginManagement>
  85. <plugins>
  86. <plugin>
  87. <artifactId>maven-antrun-plugin</artifactId>
  88. <version>1.3</version>
  89. </plugin>
  90. <plugin>
  91. <artifactId>maven-assembly-plugin</artifactId>
  92. <version>2.2-beta-5</version>
  93. </plugin>
  94. <plugin>
  95. <artifactId>maven-dependency-plugin</artifactId>
  96. <version>2.1</version>
  97. </plugin>
  98. <plugin>
  99. <artifactId>maven-release-plugin</artifactId>
  100. <version>2.0</version>
  101. </plugin>
  102. </plugins>
  103. </pluginManagement>
  104. <plugins>
  105. <plugin>
  106. <artifactId>maven-assembly-plugin</artifactId>
  107. <version>2.4</version>
  108. </plugin>
  109. <plugin>
  110. <artifactId>maven-dependency-plugin</artifactId>
  111. <version>2.8</version>
  112. </plugin>
  113. <plugin>
  114. <artifactId>maven-shade-plugin</artifactId>
  115. <version>2.3</version>
  116. <executions>
  117. <execution>
  118. <phase>package</phase>
  119. <goals>
  120. <goal>shade</goal>
  121. </goals>
  122. <configuration>
  123. <artifactSet>
  124. <includes>
  125. <include>com.codelanx:codelanxlib</include>
  126. </includes>
  127. </artifactSet>
  128. <minimizeJar>true</minimizeJar>
  129. </configuration>
  130. </execution>
  131. </executions>
  132. <configuration>
  133. <artifactSet>
  134. <includes>
  135. <include>com.codelanx:codelanxlib</include>
  136. </includes>
  137. </artifactSet>
  138. <minimizeJar>true</minimizeJar>
  139. </configuration>
  140. </plugin>
  141. <plugin>
  142. <artifactId>maven-clean-plugin</artifactId>
  143. <version>2.4.1</version>
  144. <executions>
  145. <execution>
  146. <id>default-clean</id>
  147. <phase>clean</phase>
  148. <goals>
  149. <goal>clean</goal>
  150. </goals>
  151. </execution>
  152. </executions>
  153. </plugin>
  154. <plugin>
  155. <artifactId>maven-resources-plugin</artifactId>
  156. <version>2.5</version>
  157. <executions>
  158. <execution>
  159. <id>default-testResources</id>
  160. <phase>process-test-resources</phase>
  161. <goals>
  162. <goal>testResources</goal>
  163. </goals>
  164. </execution>
  165. <execution>
  166. <id>default-resources</id>
  167. <phase>process-resources</phase>
  168. <goals>
  169. <goal>resources</goal>
  170. </goals>
  171. </execution>
  172. </executions>
  173. </plugin>
  174. <plugin>
  175. <artifactId>maven-jar-plugin</artifactId>
  176. <version>2.3.2</version>
  177. <executions>
  178. <execution>
  179. <id>default-jar</id>
  180. <phase>package</phase>
  181. <goals>
  182. <goal>jar</goal>
  183. </goals>
  184. </execution>
  185. </executions>
  186. </plugin>
  187. <plugin>
  188. <artifactId>maven-compiler-plugin</artifactId>
  189. <version>2.3.2</version>
  190. <executions>
  191. <execution>
  192. <id>default-compile</id>
  193. <phase>compile</phase>
  194. <goals>
  195. <goal>compile</goal>
  196. </goals>
  197. </execution>
  198. <execution>
  199. <id>default-testCompile</id>
  200. <phase>test-compile</phase>
  201. <goals>
  202. <goal>testCompile</goal>
  203. </goals>
  204. </execution>
  205. </executions>
  206. </plugin>
  207. <plugin>
  208. <artifactId>maven-surefire-plugin</artifactId>
  209. <version>2.10</version>
  210. <executions>
  211. <execution>
  212. <id>default-test</id>
  213. <phase>test</phase>
  214. <goals>
  215. <goal>test</goal>
  216. </goals>
  217. </execution>
  218. </executions>
  219. </plugin>
  220. <plugin>
  221. <artifactId>maven-install-plugin</artifactId>
  222. <version>2.3.1</version>
  223. <executions>
  224. <execution>
  225. <id>default-install</id>
  226. <phase>install</phase>
  227. <goals>
  228. <goal>install</goal>
  229. </goals>
  230. </execution>
  231. </executions>
  232. </plugin>
  233. <plugin>
  234. <artifactId>maven-deploy-plugin</artifactId>
  235. <version>2.7</version>
  236. <executions>
  237. <execution>
  238. <id>default-deploy</id>
  239. <phase>deploy</phase>
  240. <goals>
  241. <goal>deploy</goal>
  242. </goals>
  243. </execution>
  244. </executions>
  245. </plugin>
  246. <plugin>
  247. <artifactId>maven-site-plugin</artifactId>
  248. <version>3.0</version>
  249. <executions>
  250. <execution>
  251. <id>default-site</id>
  252. <phase>site</phase>
  253. <goals>
  254. <goal>site</goal>
  255. </goals>
  256. <configuration>
  257. <outputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\site</outputDirectory>
  258. <reportPlugins>
  259. <reportPlugin>
  260. <groupId>org.apache.maven.plugins</groupId>
  261. <artifactId>maven-project-info-reports-plugin</artifactId>
  262. </reportPlugin>
  263. </reportPlugins>
  264. </configuration>
  265. </execution>
  266. <execution>
  267. <id>default-deploy</id>
  268. <phase>site-deploy</phase>
  269. <goals>
  270. <goal>deploy</goal>
  271. </goals>
  272. <configuration>
  273. <outputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\site</outputDirectory>
  274. <reportPlugins>
  275. <reportPlugin>
  276. <groupId>org.apache.maven.plugins</groupId>
  277. <artifactId>maven-project-info-reports-plugin</artifactId>
  278. </reportPlugin>
  279. </reportPlugins>
  280. </configuration>
  281. </execution>
  282. </executions>
  283. <configuration>
  284. <outputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\site</outputDirectory>
  285. <reportPlugins>
  286. <reportPlugin>
  287. <groupId>org.apache.maven.plugins</groupId>
  288. <artifactId>maven-project-info-reports-plugin</artifactId>
  289. </reportPlugin>
  290. </reportPlugins>
  291. </configuration>
  292. </plugin>
  293. </plugins>
  294. </build>
  295. <reporting>
  296. <outputDirectory>C:\Users\Spencer\Documents\NetBeansProjects\PhanaticPrison\target\site</outputDirectory>
  297. </reporting>
  298. </project>

完整的maven堆栈跟踪:

  1. org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project phanaticprison: Error creating shaded jar: INVOKESPECIAL/STATIC on interfaces require ASM 5
  2. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
  3. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
  4. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
  5. at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
  6. at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
  7. at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
  8. at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
  9. at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
  10. at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
  11. at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
  12. at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
  13. at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
  14. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  15. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  16. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  17. at java.lang.reflect.Method.invoke(Method.java:483)
  18. at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
  19. at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
  20. at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
  21. at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
  22. Caused by: org.apache.maven.plugin.MojoExecutionException: Error creating shaded jar: INVOKESPECIAL/STATIC on interfaces require ASM 5
  23. at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:566)
  24. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
  25. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
  26. ... 19 more
  27. Caused by: java.lang.IllegalArgumentException: INVOKESPECIAL/STATIC on interfaces require ASM 5
  28. at org.objectweb.asm.MethodVisitor.visitMethodInsn(Unknown Source)
  29. at org.objectweb.asm.commons.RemappingMethodAdapter.doVisitMethodInsn(Unknown Source)
  30. at org.objectweb.asm.commons.RemappingMethodAdapter.visitMethodInsn(Unknown Source)
  31. at org.objectweb.asm.ClassReader.a(Unknown Source)
  32. at org.objectweb.asm.ClassReader.b(Unknown Source)
  33. at org.objectweb.asm.ClassReader.accept(Unknown Source)
  34. at org.objectweb.asm.ClassReader.accept(Unknown Source)
  35. at org.vafer.jdependency.Clazzpath.addClazzpathUnit(Clazzpath.java:194)
  36. at org.vafer.jdependency.Clazzpath.addClazzpathUnit(Clazzpath.java:130)
  37. at org.apache.maven.plugins.shade.filter.MinijarFilter.addDependencyToClasspath(MinijarFilter.java:101)
  38. at org.apache.maven.plugins.shade.filter.MinijarFilter.<init>(MinijarFilter.java:81)
  39. at org.apache.maven.plugins.shade.mojo.ShadeMojo.getFilters(ShadeMojo.java:805)
  40. at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:458)
  41. ... 21 more

解决方法

由于我最近遇到了同样的问题,我花了很长时间来修复它,这就是我所做的:

ASM所需的版本是5.0.3.但是,shade插件中当前可用的版本是5.0.2.看看JIRA的门票,它看起来已经在2.4中得到了修复,但是那个版本还没有为公众所用(2015年5月4日到我写这篇文章的时候).

所以你要做的就是通过将这个部分添加到你的pom来激活开发者版本(基于https://maven.apache.org/guides/development/guide-testing-development-plugins.html):

  1. <pluginRepositories>
  2. <pluginRepository>
  3. <id>apache.snapshots</id>
  4. <url>http://repository.apache.org/snapshots/</url>
  5. </pluginRepository>
  6. </pluginRepositories>

并将插件的版本设置为2.4-SNAPSHOT:

  1. <plugins>
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-shade-plugin</artifactId>
  5. <version>2.4-SNAPSHOT</version>
  6. </plugin>
  7. </plugins>

希望这可以帮助!

猜你在找的Java相关文章