1. 环境: osx+java11+idea2022.2.5+maven+powermock+junit5
  2. 问题: 项目环境java11,运行环境java17:
    powermock包使用Whitebox.invokeMethod测试调用私有/静态方法时:直接ide运行测试通过,但有警告提示, mvn clean test测试不通过并报错
  3. 解决办法: 运行环境也从java17改java11,同时修改pom.xml相关参数如下:(世界清净了: 测试ok,消除警告和报错)
  4. 其它:
    java17提示不再支持–illegal-access=permit运行参数,类似绕过安全机制方法不灵,目前本机验证改java11没问题
    另外github上有gradle相关方案参考,本质就是设置好这一串参数
    BTW: 不同jdk 通过zshrc配置alias切换不成功,请尝试去掉PATH中JAVA_HOME/bin
<groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <argLine>
                        --illegal-access=permit
                        --illegal-access=debug
                        --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED
                        --add-opens java.logging/java.util.logging=ALL-UNNAMED
                        --add-opens java.base/java.time.zone=ALL-UNNAMED
                        --add-opens java.base/java.lang.reflect=ALL-UNNAMED
                        --add-opens java.base/java.security.cert=ALL-UNNAMED
                        --add-opens java.base/java.text=ALL-UNNAMED
                        --add-opens java.base/java.net=ALL-UNNAMED
                        --add-opens java.base/java.nio.charset=ALL-UNNAMED
                        --add-opens java.base/java.nio.file=ALL-UNNAMED
                        --add-opens java.base/sun.nio.fs=ALL-UNNAMED
                        --add-opens java.base/sun.security.x509=ALL-UNNAMED
                        --add-opens java.base/java.util.regex=ALL-UNNAMED
                        --add-opens java.base/java.util.stream=ALL-UNNAMED
                        --add-opens java.base/java.util.concurrent=ALL-UNNAMED
                        --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED
                        --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED
                        --add-opens java.base/java.time=ALL-UNNAMED
                        --add-opens java.base/java.util=ALL-UNNAMED
                        --add-opens java.base/java.io=ALL-UNNAMED
                        --add-opens java.base/java.lang=ALL-UNNAMED
                    </argLine>```

 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐