从 Gradle 运行 Ant 脚本

2024-02-28

我正在尝试从 Gradle 运行 ant 脚本,但有一个例外:

  Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.

我宁愿使用本地库中的 ant-junit,但我不知道如何使用,我对 Gradle 还很陌生。

我找到了这段代码

configurations { 
  antClasspath 
} 
dependencies { 
  antClasspath 'org.apache.ant:ant-junit4:1.8.3' 
} 
ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader 
configurations.antClasspath.each { File f -> 
  antClassLoader.addURL(f.toURI().toURL()) 
} 

但我不知道如果 jar 已经在 mt lib 文件夹中我必须更改什么。我不想使用 Maven 存储库。


这只是从评论中转发的,它解决了我的问题:感谢Opal https://stackoverflow.com/users/542270/opal

在没有网络连接的情况下运行 gradle 可能不是一个好主意。不过,如果您在本地目录中有所需的 jar,只需使用文件依赖项将 id 添加到脚本依赖项即可。看:http://www.gradle.org/docs/current/userguide/dependency_management.html#file-dependencies http://www.gradle.org/docs/current/userguide/dependency_management.html#file-dependencies来自蛋白石

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Gradle 运行 Ant 脚本 的相关文章

随机推荐