You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用yGuard混淆Maven项目时maven.runtime.classpath属性未解析的解决办法

解决yGuard混淆Maven项目时的"Unsolved maven property maven.runtime.classpath"错误

错误原因是maven.runtime.classpath这个引用ID未被正确识别或初始化,下面是两种可行的解决方法:

方法一:直接给maven-antrun-plugin添加yGuard依赖

修改pom.xml配置,将yGuard依赖添加到maven-antrun-plugin的依赖列表中,让插件运行时直接加载yGuard类,无需依赖外部classpath引用:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <id>obfuscate</id>
            <configuration>
                <tasks>
                    <!-- 移除原有的property和classpath配置,直接定义taskdef -->
                    <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask"/>
                    <yguard>
                        <!-- 使用Maven内置变量替代硬编码文件名,适配性更强 -->
                        <inoutpair in="${project.build.finalName}.jar" out="${project.build.finalName}-obf.jar" />
                    </yguard>
                </tasks>
            </configuration>
        </execution>
    </executions>
    <!-- 给插件添加yGuard依赖 -->
    <dependencies>
        <dependency>
            <groupId>com.yworks</groupId>
            <artifactId>yguard</artifactId>
            <version>3.1.0</version> <!-- 根据需求调整版本 -->
        </dependency>
    </dependencies>
</plugin>

方法二:替换为可用的classpath引用

如果坚持使用classpath引用方式,可将maven.runtime.classpath替换为maven.plugin.classpath,这个引用ID在maven-antrun-plugin中是可靠可用的:

<tasks>
    <property name="runtime_classpath" refid="maven.plugin.classpath"/>
    <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${runtime_classpath}"/>
    <yguard>
        <inoutpair in="${project.build.finalName}.jar" out="${project.build.finalName}-obf.jar" />
    </yguard>
</tasks>

注意:此方法仍需确保yGuard依赖已正确引入到项目或插件的依赖中。

内容的提问来源于stack exchange,提问作者syncnet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 14:02:51