问题
We use Artifactory to store our maven generated java artifacts. We have many interrelated projects that depend on each other. Is it possible with maven or with Artifactory to look pick a single artifact and look for all projects that have that as a dependency?
In the example below, I want to find what projects use artifact1 v1.0.0. I would like to be able to use maven/Artifactory to find the fact that artifact2 depends on this version of the dependency, but not find artifact3/4 which don't. Ideally it would also be nice to find artifact2 if I was just looking for uses of artifact1 regardless of version.
<project>
<groupId>mygroup</groupId>
<artifactId>artifact1</artifactId>
<version>1.0.0</version>
</project>
<project>
<groupId>mygroup</groupId>
<artifactId>artifact2</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>artifact1</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
<project>
<groupId>mygroup</groupId>
<artifactId>artifact3</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>artifact1</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
<project>
<groupId>mygroup</groupId>
<artifactId>artifact4</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>otherartifact</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
回答1:
This is pretty much one of the main reasons why you would use Artifactory in the first place. Artifactory provides a very extensive search capability in the form of its AQL, which does exactly what you're asking for.
As an example for your case running something like:
builds.find(
{"module.dependency.item.name":{"$match":"*artifact1*"}}
).include("module.artifact.name")
will return all builds that had Artifact1 as a dependency (you can also add an "$and" clause to limit this to a specific version of Arifact1), the include at the end will return all artifacts that were part of the module that had Artifact1 as a dependency (so that's where you will see Artifact2 in your case)
Here is an example output I got when running this query on a simple maven build called multi-module-build that had several modules where one of them (multi3) had a dependency called multi1:
"results" : [ {
"build.created" : "2016-03-10T09:08:51.283+02:00",
"build.created_by" : "admin",
"build.name" : "multi-module-build",
"build.number" : "10",
"build.url" : "http://localhost:9090/jenkins/job/multi-shmulti/10/",
"modules" : [ {
"artifacts" : [ {
"artifact.name" : "multi3-3.6-SNAPSHOT.war"
}, {
"artifact.name" : "multi3-3.6-SNAPSHOT.pom"
} ]
} ]
} ]
来源:https://stackoverflow.com/questions/35888073/find-what-other-projects-use-this-project-as-a-maven-dependency