将工件上传到Nexus 3

时间:2016-09-21 09:54:10

标签: maven gradle nexus

我正在尝试将工件上传到Nexus 3.我已经设法成功完成了它,但是当我查看UI时看起来事情没有正确分组。

我可以使用curl或maven以下配置和URL。

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://localhost:8081/repository/my-snapshot/") {
                authentication(userName: "admin", password: "admin123")
            }
            pom.version = "${version}-SNAPSHOT"
            pom.artifactId = "my-server"
            pom.groupId = "com.example"
        }
    }
}

但是当我这样做时,工件没有分组,因此我可以通过它的版本删除目录。我必须删除每个文件:

enter image description here

这是Nexus 3的限制吗?

1 个答案:

答案 0 :(得分:0)

还有一个'组件视图',用于对每个人工制品进行分组

enter image description here

但是如果您正在了解如何根据artefact id和版本删除组件的信息: 你可以通过nexus api实现它

https://books.sonatype.com/nexus-book/reference3/scripting.html读取ch16,向您介绍脚本方式 那里的答案显示了如何列出回购中的所有文物。我把它扩展到了这里:

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")