[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on proj

本文记录了使用Maven编译Scala项目时遇到的错误,包括类文件损坏及类型不匹配等问题,并提供了相应的解决办法。

maven编译异常错误loading CharSequence class file is broken

标签: maven broken
1292人阅读  评论(0)  收藏  举报
  分类:
java/scala(5) 

  在用maven对项目进行编译打包时,遇到了下面奇怪的编译错误

[plain]  view plain  copy
  1. "C:\Program Files\Java\jdk1.8.0\bin\java" "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3\bin\m2.conf" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=2016.2.1 -s D:\apache-maven-3.2.5\conf\settings.xml package  
  2. [INFO] Scanning for projects...  
  3. [WARNING]   
  4. [WARNING] Some problems were encountered while building the effective model for com.fangdd.data:house-profile:jar:1.0-SNAPSHOT  
  5. [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-install-plugin is missing. @ line 181, column 21  
  6. [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ line 173, column 21  
  7. [WARNING]   
  8. [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.  
  9. [WARNING]   
  10. [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.  
  11. [WARNING]   
  12. [INFO]                                                                           
  13. [INFO] ------------------------------------------------------------------------  
  14. [INFO] Building house-profile 1.0-SNAPSHOT  
  15. [INFO] ------------------------------------------------------------------------  
  16. [INFO]   
  17. [INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ house-profile ---  
  18. [INFO]   
  19. [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ house-profile ---  
  20. [debug] execute contextualize  
  21. [INFO] Using 'UTF-8' encoding to copy filtered resources.  
  22. [INFO] skip non existing resourceDirectory D:\git-repository\house-profile\src\main\resources\prod  
  23. [INFO] Copying 4 resources  
  24. [INFO]   
  25. [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ house-profile ---  
  26. [INFO] Nothing to compile - all classes are up to date  
  27. [INFO]   
  28. [INFO] --- scala-maven-plugin:3.2.2:compile (default) @ house-profile ---  
  29. [WARNING]  Expected all dependencies to require Scala version: 2.10.0  
  30. [WARNING]  com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4  
  31. [WARNING] Multiple versions of scala libraries detected!  
  32. [INFO] D:\git-repository\house-profile\src\main\java:-1: info: compiling  
  33. [INFO] D:\git-repository\house-profile\src\main\scala:-1: info: compiling  
  34. [INFO] Compiling 27 source files to D:\git-repository\house-profile\target\classes at 1498550091810  
  35. [ERROR] error: error while loading CharSequence, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/lang/CharSequence.class)' is broken  
  36. [INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 1501)  
  37. [ERROR] error: error while loading AnnotatedElement, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/lang/reflect/AnnotatedElement.class)' is broken  
  38. [INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 2713)  
  39. [ERROR] error: error while loading ConcurrentMap, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/util/concurrent/ConcurrentMap.class)' is broken  
  40. [INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 2447)  
  41. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemAddressProcessor.scala:21: error: overloaded method value replaceAllIn with alternatives:  
  42. [ERROR]   (target: CharSequence,replacer: scala.util.matching.Regex.Match => String)String <and>  
  43. [ERROR]   (target: CharSequence,replacement: String)String  
  44. [ERROR]  cannot be applied to (String, String)  
  45. [ERROR]       val addressReg = Constants.SPECIAL_CHAR_REG.r.replaceAllIn(address, "")  
  46. [ERROR]                                                     ^  
  47. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:24: error: type mismatch;  
  48. [ERROR]  found   : String  
  49. [ERROR]  required: CharSequence  
  50. [ERROR]       if (StringUtils.isNotBlank(name)) {  
  51. [ERROR]                                  ^  
  52. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:44: error: type mismatch;  
  53. [ERROR]  found   : String  
  54. [ERROR]  required: CharSequence  
  55. [ERROR]       if (StringUtils.isNotBlank(name)) {  
  56. [ERROR]                                  ^  
  57. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:55: error: overloaded method value indexOf with alternatives:  
  58. [ERROR]   (CharSequence,CharSequence)Int <and>  
  59. [ERROR]   (CharSequence,Int)Int  
  60. [ERROR]  cannot be applied to (String, String)  
  61. [ERROR]          val baseName = StringUtils.substring(tmp1, 0, StringUtils.indexOf(tmp1, ""))  
  62. [ERROR]                                                                    ^  
  63. [ERROR] error: error while loading Pattern, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/util/regex/Pattern.class)' is broken  
  64. [INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 14717)  
  65. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:127: error: type mismatch;  
  66. [ERROR]  found   : String  
  67. [ERROR]  required: CharSequence  
  68. [ERROR]             if (StringUtils.equals(srcNameNormalized, tgtNameNormalized)) {  
  69. [ERROR]                                    ^  
  70. [ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\util\ItemAddressProcessor.scala:22: error: overloaded method value replaceAllIn with alternatives:  
  71. [ERROR]   (target: CharSequence,replacer: scala.util.matching.Regex.Match => String)String <and>  
  72. [ERROR]   (target: CharSequence,replacement: String)String  
  73. [ERROR]  cannot be applied to (String, String)  
  74. [ERROR]       val addressReg = Constants.SPECIAL_CHAR_REG.r.replaceAllIn(address, "")  
  75. [ERROR]                                                     ^  
  76. [ERROR] 10 errors found  
  77. [INFO] ------------------------------------------------------------------------  
  78. [INFO] BUILD FAILURE  
  79. [INFO] ------------------------------------------------------------------------  
  80. [INFO] Total time: 7.241s  
  81. [INFO] Finished at: Tue Jun 27 15:54:55 CST 2017  
  82. [INFO] Final Memory: 19M/259M  
  83. [INFO] ------------------------------------------------------------------------  
  84. [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project house-profile: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]  
  85. [ERROR]   
  86. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
  87. [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
  88. [ERROR]   
  89. [ERROR] For more information about the errors and possible solutions, please read the following articles:  
  90. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException  
  91.   
  92. Process finished with exit code 1  

最后发现是maven编译插件配置的原因,编译插件版本不完整配置的是scala.binary.version,应该采用完整版本scala.complete.version才能找到具体的class

[html]  view plain  copy
  1.  <properties>  
  2.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  3.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
  4.         <java.version>1.8</java.version>  
  5.         <maven.version.min>3.0.5</maven.version.min>  
  6.         <scala.binary.version>2.11</scala.binary.version>  
  7.         <scala.complete.version>${scala.binary.version}.4</scala.complete.version>  
  8.         <spark.version>1.6.2</spark.version>  
  9.         <spark-sql.version>1.6.2</spark-sql.version>  
  10.         <spark-hive.version>1.6.2</spark-hive.version>  
  11.  </properties>  
  12.   
  13. <plugin>  
  14.     <groupId>net.alchim31.maven</groupId>  
  15.     <artifactId>scala-maven-plugin</artifactId>  
  16.     <version>3.2.2</version>  
  17.     <configuration>  
  18.         <scalaVersion>${scala.complete.version}</scalaVersion>  
  19.         <args>  
  20.             <arg>-unchecked</arg>  
  21.             <arg>-deprecation</arg>  
  22.             <arg>-feature</arg>  
  23.         </args>  
  24.         <javacArgs>  
  25.             <javacArg>-source</javacArg>  
  26.             <javacArg>${java.version}</javacArg>  
  27.             <javacArg>-target</javacArg>  
  28.             <javacArg>${java.version}</javacArg>  
  29.         </javacArgs>  
  30.     </configuration>  
  31.     <executions>  
  32.         <execution>  
  33.             <phase>compile</phase>  
  34.             <goals>  
  35.                 <goal>compile</goal>  
  36.             </goals>  
  37.         </execution>  
  38.     </executions>  
  39. </plugin>  
<think>好的,我现在需要解决用户在使用scala-maven-plugin3.2.2时,在gyspark项目的testCompile阶段遇到的执行失败问题。首先,我得回忆一下常见的导致Maven插件失败的原因。通常,这类问题可能涉及依赖冲突、插件版本不兼容、Scala版本与插件不匹配、缓存问题或者项目配置错误。根据用户提供的引用内容,尤其是引用[4]中提到隐式转换的问题,可能需要检查代码中的隐式转换是否正确。另外,引用[3]提到IDEA运行Scala代码时的编译错误,可能涉及到IDE配置或者插件设置。用户之前的问题可能与Scala和Java版本的兼容性有关,所以需要确认项目的Scala版本是否与插件支持的版本一致。scala-maven-plugin3.2.2可能对Scala2.11或2.12有特定要求,如果项目使用的是其他版本,可能会出问题。接下来,我需要分步骤思考解决方案。首先,建议用户检查Scala版本和插件的兼容性。如果版本不匹配,升级或降级插件版本可能有效。其次,清理Maven缓存,有时候旧的依赖会导致编译失败。然后,检查项目的POM文件,确认插件配置是否正确,特别是testCompile阶段的配置是否有误。另外,查看具体的错误日志,定位到哪个文件或代码行导致失败,比如是否有隐式转换缺失,如引用[4]中的例子,可能需要添加隐式声明。 还有,考虑依赖冲突的可能性,使用Maven的依赖树分析工具(如mvndependency:tree)来排查是否有冲突的库。此外,确保IDEA中的Maven配置与命令行一致,避免IDE特有的问题。如果问题依然存在,尝试在插件配置中指定强制语言混合模式,或者调整构建顺序,确保Scala代码在Java之前编译。最后,如果所有方法都无效,可能需要寻求更详细的错误信息,例如启用Maven的调试模式(-X参数)来获取更多上下文,从而精准定位问题根源。同时,参考社区或官方文档中类似问题的解决方案,可能找到特定的修复方法。</think>### 解决 `scala-maven-plugin` 在 `testCompile` 阶段执行失败的步骤 #### 1. **检查 Scala 与插件版本兼容性** - **问题根源**:`scala-maven-plugin` 的版本与项目使用的 Scala 版本不兼容可能导致编译失败。例如,Scala 2.11 与 Scala 2.12 的二进制文件不兼容[^3]。 - **解决方案**: - 在 `pom.xml` 中确认 Scala 版本与插件配置是否匹配: ```xml <properties> <scala.version>2.11.12</scala.version> <!-- 例如适配 Scala 2.11 --> </properties> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.2.2</version> </plugin> ``` - 若版本不匹配,尝试升级插件到 `4.8.1`(支持 Scala 2.13/3.x)或调整 Scala 版本。 #### 2. **清理缓存并重新构建** - **问题根源**:Maven 本地仓库的依赖损坏可能导致编译失败。 - **操作命令**: ```bash mvn clean scala:clean install -DskipTests ``` #### 3. **检查隐式转换或代码兼容性** - **问题根源**:Scala 代码中缺少隐式转换(如引用[4]中的案例)或依赖库未正确导入。 - **解决方案**: - 在代码中显式添加隐式作用域,例如: ```scala import spark.implicits._ // 若涉及 Spark 隐式转换 ``` - 确保测试代码的依赖项(如 `scalatest`)在 `pom.xml` 中正确声明: ```xml <dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_2.11</artifactId> <version>3.0.9</version> <scope>test</scope> </dependency> ``` #### 4. **强制指定语言混合模式** - **问题根源**:Java 与 Scala 代码编译顺序冲突。 - **解决方案**:在插件配置中明确指定编译顺序: ```xml <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.2.2</version> <executions> <execution> <id>scala-compile-first</id> <phase>process-resources</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>scala-test-compile</id> <phase>process-test-resources</phase> <goals> <goal>testCompile</goal> </goals> </execution> </executions> </plugin> ``` #### 5. **检查依赖冲突** - **操作命令**: ```bash mvn dependency:tree -Dincludes=org.scala-lang ``` - **结果处理**:若存在多个 Scala 版本依赖,需在 `pom.xml` 中通过 `<exclusion>` 排除冲突项。 #### 6. **启用 Maven 调试模式** - **操作命令**: ```bash mvn -X test-compile ``` - **分析重点**:根据日志定位具体报错位置(如缺失类、语法错误或资源路径问题)。 --- ### 典型错误场景与修复 1. **隐式转换缺失** - **错误示例**:`could not find implicit value for parameter encoder: Encoder[...]` - **修复方法**:在测试类中导入 Spark 的隐式作用域[^4]。 2. **Scala 版本不匹配** - **错误示例**:`scala.reflect.internal.MissingRequirementError` - **修复方法**:同步 `pom.xml` 中的 Scala 版本与项目代码。 ---
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值