【问题标题】:Automating component deletion in Nexus 3在 Nexus 3 中自动删除组件
【发布时间】:2016-12-20 03:15:28
【问题描述】:

我正在尝试通过 nexus 3 api 删除存储库中的一些组件

我已按照以下问题中的说明进行操作 Using the Nexus3 API how do I get a list of artifacts in a repository

并对其进行了如下修改以删除工件

import groovy.json.JsonOutput
import org.sonatype.nexus.repository.storage.Component
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet

def repoName = "eddie-test"
def startDate = "2016/01/01"
def artifactName = "you-artifact-name"
def artifactVersion = "1.0.6"

log.info(" Attempting to delete for repository: ${repoName} as of startDate: ${startDate}")

def repo = repository.repositoryManager.get(repoName)
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()

tx.begin()

// build a query to return a list of components scoped by name and version
Iterable<Component> foundComponents = tx.findComponents(Query.builder().where('name = ').param(artifactName).and('version = ').param(artifactVersion).build(), [repo])

// extra logic for validation goes here
if (foundComponents.size() == 1) {
    tx.deleteComponent(foundComponents[0])
}

tx.commit()
log.info("done")

但是,当我询问 maven-metadata.xml 时 http://localhost:32769/repository/eddie-test/com/company/you-artifact-name/maven-metadata.xml 该版本仍然列出。 即

<metadata>
   <groupId>com.company</groupId>
   <artifactId>you-artifact-name</artifactId>
   <versioning>
       <release>1.0.7</release>
       <versions>
           <version>1.0.6</version>
           <version>1.0.7</version>
       </versions>
       <lastUpdated>20161213115754</lastUpdated>
   </versioning>

(通过 ui 中的删除组件按钮删除组件,按预期更新 maven-metadata.xml)

那么有没有办法确保通过 API 删除文件时更新文件?

【问题讨论】:

    标签: nexus


    【解决方案1】:

    运行后,您可以运行重建 Maven 存储库元数据计划任务,这将完成您的目标。

    目前没有用于调用该任务的公共 API。如果您愿意,请转到https://issues.sonatype.org/browse/NEXUS 并为此提出问题:)

    【讨论】:

    猜你喜欢
    • 2017-11-22
    • 2016-07-19
    • 1970-01-01
    • 2018-07-25
    • 2018-01-17
    • 1970-01-01
    • 2018-02-16
    • 2015-10-31
    • 1970-01-01
    相关资源
    最近更新 更多