我有一个本地存储库,其中的工件作为 m2 兼容存储库发布。
<filesystem name="local" m2compatible="true" local="true">
<ivy pattern="${ivy.local.default.root}/[organization]/[module]/[revision]/[module]-[revision](-[classifier]).pom" />
<artifact pattern="${ivy.local.default.root}/[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]" />
</filesystem>
ivy 信息的组织中有“.”。
例如,
<info organization="com.github.org" module="module" rev="0.1" status="release"/>
当工件发布时,它们最终会出现在如下目录中:
/.ivy2/local/com/github/org/module/0.1/*
删除任务设置如下:
<delete dir="${ivy.local.default.root}/${ivy.organization}/${ivy.module}/${ivy.revision}"/>
我相信这不起作用,因为 ivy.organization
没有分成单独的目录来执行删除任务。
如何设置项目以正确删除已发布的 jar 文件?
最佳答案
可以通过一些脚本来对要转换为文件路径片段的字符串调用String.replaceAll()
。例如,使用以下macrodef
:
<!-- =============================================================================
Replaces all '.' in groupId with '/' and put the result in a property
Attributes:
- groupId: maven groupId
- result: name of the property in which to put the result
============================================================================== -->
<macrodef name="pathFrom">
<attribute name="groupId"/>
<attribute name="result" default="path"/>
<sequential>
<local name="g"/>
<property name="g" value="@{groupId}"/>
<script language="javascript">
project.setProperty("@{result}", project.getProperty("g").replaceAll("\\.", "/"));
</script>
</sequential>
</macrodef>
这是一个示例用法:
<target name="test">
<property name="myGroup" value="com.github.org"/>
<pathFrom groupId="${myGroup}" result="tmp.path"/>
<echo message="converted from '${myGroup}' to '${tmp.path}'"/>
</target>
使用 ant test
调用时具有以下输出:
test:
[echo] converted from 'com.github.org' to 'com/github/org'
关于java - 从 ivy 本地存储库中删除的 Ant 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53782891/