goo*_*ead 5 nexus maven nexus3
众所周知,Nexus 3还没有REST API,这对我来说非常奇怪.我只能使用wget或curl手动下载工件.但是当我使用Maven 3时,所有快照工件都使用如下的时间戳命名:
myartifact-1.0-20161215.141522-4.tar.gz
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何从回购中获取最新的快照?我想自动化工件的下载过程,但随着名称的改变,我没有找到任何方法来实现这一点.
谢谢.
您可以在Groovy中创建一个脚本并将其上传到Nexus以执行您想要的操作.
这是我用来编写的脚本示例,用于返回给定组和存储库的所有版本.
内容version.json:
{
"name": "version",
"type": "groovy",
"content": "import org.sonatype.nexus.repository.storage.Query;
import org.sonatype.nexus.repository.storage.StorageFacet;
import groovy.json.JsonOutput;
def groupId = args.split(',')[0];
def repositoryId = args.split(',')[1];
def repo = repository.repositoryManager.get(repositoryId);
StorageFacet storageFacet = repo.facet(StorageFacet);
def tx = storageFacet.txSupplier().get();
tx.begin();
def components = tx.findComponents(Query.builder().where('group = ').param(groupId).build(), [repo]);
def found = components.collect {
def baseVersion = it.attributes().child('maven2').get('baseVersion');
\"${baseVersion}\"
};
found = found.unique();
tx.commit();
def result = JsonOutput.toJson(found);
return result;"
}
Run Code Online (Sandbox Code Playgroud)
这里有趣的部分是tx.findComponents()返回泛型Component类.这个类提供了有关其额外信息的容器与功能attributes().然后,您可以使用它来获取baseVersionMaven以前使用的版本(带-SNAPSHOT后缀).
要安装此脚本,只需运行以下命令:
curl -v -X POST -u <NEXUS_ADMIN>:<NEXUS_PWD> --header "Content-Type:application/json" http://<SERVER_NEXUS>/nexus/service/siesta/rest/v1/script -d @version.json
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下方法轻松测试:
curl -v -X POST -u <NEXUS_ADMIN>:<NEXUS_PWD> --header "Content-Type: text/plain" "http://<SERVER_NEXUS>/nexus/service/siesta/rest/v1/script/version/run" -d "com.my.groupid,snapshots"
Run Code Online (Sandbox Code Playgroud)
这将返回您想要的所有版本:
{
"name" : "version",
"result" : "[\"1.5.2-SNAPSHOT\",\"1.5.3-SNAPSHOT\",\"1.6.1-SNAPSHOT\",\"1.5.0-SNAPSHOT\"]"
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助!
此API调用将起作用: ${nexusUrl}/service/rest/beta/search/assets/download?maven.groupId=${groupId}&maven.artifactId=${artifactId}&maven.baseVersion=${version}
尽管最终有了Nexus3 API(请参阅Sonatype的博客中的更多内容),但该API尚未提供获取最新SNAPSHOT版本的方法。希望将来可以改善这种情况:NEXUS-14407正在跟踪此功能请求。
但是直到那时,我都通过定义一个Maven - Delete SNAPSHOTTask来解决该问题:
并将其配置为每分钟运行一次,以删除除0天之前的1个快照版本以外的所有快照版本:
| 归档时间: |
|
| 查看次数: |
5592 次 |
| 最近记录: |