I'm new to writing nexus plugins. From my plugin, I have a scheduled task. When the task is executed, I want to find all the artifacts in the configured repository that have an item with a certain maven classifier.
I'm injecting a RepositoryRegistry, getting a repository by id, and using List org.sonatype.nexus.proxy.repository.Repository.list(ResourceStoreRequest), but it only returns locally stored items. Is there a container managed component I could inject or a utility that will give me a List or Tree of items in the index?
I've looked at the lucene search api, but it requires a group, artifact, or version... I can't search by classifier. I've also looked at some of the sisu packages, but couldn't find anything.
For example
Repository Proxy named MyRemote
contains /my/group/artifactA/1/xml/features
Repository Hosted named MyHosted
contains /my/group/artifactB/1/xml/features
Repository Group named MyGroup that contains MyRemote and MyHosted
I'm think I'm looking for a java API that will give me one of the following:
#Inject IndexManager??
List SomeUtil.searchRepo(..., String classifier, ...)
Tree SomeUtil.getIndexTree(String repoId)
and will list out both the my.group:artifactA:1:xml:features and my.group:artifactB:1:xml:features
Thanks!
Problem answered on the Nexus users list, FTR:
http://maven.40175.n5.nabble.com/Nexus-Plugin-Reading-Indexes-td5771952.html
Related
I am trying to block overwriting in JFrog Artifactory. I have a two Maven repos: one for snapshot versions and another for releases, the first one should allow overwriting while the second one doesn't. As I can see it must be configured at user level (How can I prevent previously deployed artifacts from being overwritten?) but I would need to do it at repo level. Is there any way to do it? Maybe it is possible configuring Maven?
There is an option to use Include and Exclude Patterns at the repo level.
The Include Patterns and the Exclude Patterns fields provide a way to filter out specific repositories when trying to resolve the location of different artifacts.
In each field you can specify a list of Ant-like patterns to filter in and filter out artifact queries. Filtering works by subtracting the excluded patterns (default is none) from the included patterns (default is all).
Finally I've implemented the solution based in user permissions. It seems to be the only way of doing it and works for me.
How do I know which Group Ids are already registered in the Maven Repository?
I recently tried to publish a plugin in the Maven Repository, however, I got the message that the GroupId I used in the project was already in use. I searched the internet to find out which GroupsIds are already registered, but I didn't find anything.
Your actual question
I'm not aware of any specific list of all Group IDs, but you can check by searching for individual groups at https://search.maven.org/, using the g: query operator.
For instance, to find anything published by com.saucelabs, you can search for g:com.saucelabs, which returns this list.
A followup question
Maven requires that the Group ID follows the Java package naming rules. That means "it starts with a reversed domain name you control". This isn't always the case for legacy projects, but they warn that new projects not following this rule might find it difficult to get included in the repo.
If you do belong to an organisation controlling that group, you'll need to collaborate with the existing publishers in your organization to get permissions to deploy new artifacts with the same group, and likely add a new subgroup (eg, com.saucelabs.examples is a subgroup of com.saucelabs)
You can read more about Maven Co-ordinates here: https://maven.apache.org/guides/mini/guide-naming-conventions.html.
And there are also some Sonatype guidelines here: https://central.sonatype.org/publish/#individual-projects-open-source-software-repository-hosting-ossrh
I've seen a lots of posts around Maven and multiple repositories with single server credentials like this one.
However the general given solution is always for deploying artifact with the distributionManagement tag, which is not the needed answer. (we need to install deps -> repositories tag is needed)
Is there any other solution than having two duplicated server entries with same credentials but different ids?
Rather than using two credential entries, the other solution is to set the first repository in the parent pom of your project (or creating one) and the second repository in the child pom
-> you will be able to use the same ID for your repository without having the duplicate error.
We use sonatype nexus. We want to have common repository that will hold all the artifacts in our organization and the child repositories for each project in organization. The goal we want to achieve is to have all artifacts physically located in common repository and some(I dont know how to correct call it in terms of nexus) links from project repositories to common repositories, so the project repositories will not have physically located artifacts just links to them.
Why we need this? Just to separate artifacts as per project using, but not have cloned artifacts in each project repos.
I've analysed proxy, virtual types of repos and went through nexus documentation. Is this actually doable in nexus?
As this post explained, there really only two ways to design your repositories layout: one per project/team or single repo for the entire organization but partitioning by the group id: https://support.sonatype.com/hc/en-us/articles/213465778-What-approach-should-I-use-to-restrict-access-to-artifacts-in-Nexus-
Use one repo per project, then group them, so they all can be referenced from one single group URL. Access control can be done at per repo level so only this project can upload to this repo.
Use one single repo for the entire organization but partitioned by the group id, e.g. it will look like this, org.yourcompany.projectname.artifactid. Then you can define the repository target .projectname. to access control to this partition.
I think you actually want a Group, not a repository. A repo represents a single root directory on a disk or is a proxy of a single repo elsewhere accessible by http/s. These things are not nestable.
However, groups hold many repositories. You could create a group for each project team, containing only the repos they need, each of which could be separated by whatever criteria you want.
For example, you could have a repo that holds java DAO libs for sql databases, and another repo that holds java DAO libs for no-sql databases, yet another that contains SOAP apis, and another that holds REST apis. You could then create two groups -- say, 'modern' and 'old-school' and assign the appropriate repos to each. You could give access to the 'old-school' group to your 'serious' java devs, and 'modern' to your android script-kiddies.
I'm not suggesting that this is a particularly good breakdown -- it's just an example.
At one place where I worked we had internationally separated teams, and each had access to their own libs and central, so we had a group per country. In another place we had mobile dev and server dev, each requiring their own groups.
Maven eclipse plugin can search available dependencies from the default repositories and any additional repositories configured, given that I know the partial group Id or partial artifact Id. This is really useful in finding the available dependencies. Is there a similar mechanism available using maven in command line.
Example: suppose I know only "mybatis", and I intend to find the proper group id, artifact id, and version and whether type jar is available or not. I can easily do this using eclipse search dependency. But without eclipse do I really need to use the browser and go to repo2.maven.org (and now I find that directory browsing of this has been disabled).
First, you can search the sonatype repository, which covers a lot of ground. (I'm not sure how many other repo's are mirrored though this. I guess that's a separate question.)
Second, nexus itself has an API that you can use to script queries against the repository. For example, you can use Ruby or Groovy and do something like (assuming groovy is installed; I'm on linux):
$ cat foo.groovy
#!/usr/bin/env groovy
def xml = args.length < 2 ?
"http://repository.sonatype.org/service/local/data_index?q=" + args[0] :
"http://repository.sonatype.org/service/local/data_index?g=${args[0]}&a=${args[1]}&v=${args[2]}"
println "Searching: " + xml
def root = new XmlParser().parseText( xml.toURL().text )
root.data.artifact.each {
println "${it.groupId.text()}:${it.artifactId.text()}:${it.version.text()}"
}
Then,
$ ./foo.groovy org.mybatis mybatis 3.0.4
Searching: http://repository.sonatype.org/service/local/data_index?g=org.mybatis&a=mybatis&v=3.0.4
org.mybatis:mybatis:3.0.4
org.mybatis:mybatis:3.0.4
org.mybatis:mybatis:3.0.4
Or, closer your question (output truncated),
$ ./foo.groovy mybatis
Searching: http://repository.sonatype.org/service/local/data_index?q=mybatis
org.mybatis:mybatis:3.0.1
org.mybatis:mybatis:3.0.1
...
org.mybatis.caches:mybatis-caches-parent:1.0.0-RC1
org.mybatis.caches:mybatis-ehcache:1.0.0-RC1
org.mybatis.caches:mybatis-ehcache:1.0.0-RC1
...
org.apache.camel:camel-mybatis:2.7.0
org.apache.servicemix.bundles:org.apache.servicemix.bundles.mybatis:3.0.2_1
Note that this assumes you're querying an existing nexus maven repo, and in addition this is just searching that single repo. (So it's not exactly what you asked.)
But, actually, this is the way I want it to be: my only repository used by my maven projects is a single, internal (intranet) nexus server, and it functions as a mirror (and cache) of all the 3rd party repositories that I currently need. If I decide I need to pull in other jars from another repo (e.g., googlecode or company XYZ...), then I add that repo's url to my internal nexus configuration. Everyone on my team -- netbeans/eclipse/mvn users -- always point to the single internal maven repo, & everyone automatically picks up the newly available artifacts.
Then you can still use the above script to search for an artifact. (Note: it lets you do a generic search, or a GAV (group/artifact/version) search.)
If you're not sure which repository a given artifact is in, I guess there's always http://mvnrepository.com/