Is there any way to exclude a dependency from its parent? - maven

So there is a dependency that my project needs, and it is in our internal artifactory, however, after adding the dependency, it started throwing the following error:
Failed to read artifact descriptor for
org.codehaus.fabric3.api:commonj:jar:1.1.0: Failure to find
org.codehaus.fabric3.api:parent-pom:pom:1.0 in
http://maven/artifactory/libs-snapshot was cached in the local
repository, resolution will not be reattempted until the update
interval of art_central has elapsed or updates are forced -> [Help 1]
I realized that the parent of that dependency ( org.codehaus.fabric3.api:parent-pom:pom:1.0) is not in our internal artifactory.
I know my question might not sound logical and it doesn't make much sense but; is there any way to exclude the parent or make this dependency not look for the parent? I already try with the tag.
Thanks in advance!

You can exclude a specific file from being searched on a remote repository by using the include/exclude parameters of the remote repository.
https://www.jfrog.com/confluence/display/RTF/Common+Settings#CommonSettings-IncludesandExcludesPattern
By adding this file, Artifactory will not search for it on the specific repository.

Related

Is there a way in Gradle to define what patterns of artifacts should, (or should not), be resolved via a repository?

Is there a way in Gradle to explicitly define where certain artifacts should be coming from?
We have a legacy project which is being on-boarded to use a proper artifact repository manager, instead of a network share. However, we have multiple repositories from which artifacts are being downloaded. We'd like to be able to fine-grain where certain artifacts should be coming from, until we can fully on-board to the artifact repository manager in question.
Is something like this possible?
Yes that is possible as of Gradle 5.1
https://docs.gradle.org/5.1/release-notes.html#repository-to-dependency-matching
Repository to dependency matching
It is now possible to match repositories to dependencies, so that Gradle doesn't search for a dependency in a repository if it's never going to be found there.
See the docs for more details: https://docs.gradle.org/5.6.2/userguide/declaring_repositories.html#sec::matching_repositories_to_dependencies

How do I prevent maven from checking a remote repository for certain artifacts?

In order to include a specific maven dependency, I included its repository in my pom. Because of this, maven will check every repository for every artifact. This repository is rather slow so I would rather have maven only reach out to it when checking for the dependencies that it provides.
Is there a way to limit maven to check a repository for certain artifacts? Perhaps certain group IDs?
I doubt that you can impose such filters, but Maven asks the repositories in a certain order until it finds the artifact. As we handle this problem through Nexus, I am not experienced in this, but the question How to set order of repositories in Maven settings.xml gives (maybe outdated) information about this.

Unable to determine if resource XXXX exists in http://download.java.net/maven/2

Our builds generate a lot of errors like:
Unable to determine if resource XXXX exists in http://download.java.net/maven/2
I know this repository is gone, but I cannot locate the reference to it. If I look at the effective POM using Eclipse, the only repositories other than our internal one are:
http://repo1.maven.org/maven2
http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository
and the pluginRepository is
https://repo.maven.apache.org/maven2
The errors does break anything, but it would be nice for them to go away. Any ideas on what might be referencing this java.net URL? Perhaps some Maven plugin?

How to limit the dependencies downloaded by Maven?

Has Maven some security parameter to limit the number or depth of dependencies downloaded to the local repository when building a pom?
Imagine an artifacts repository hacked in a way that, for every artifact dummy-1.0 requested, it serves dinamically a dummy-1.0 which has a dependency on dummy-1.1, and so on.
Has Maven some security mechanism to avoid such an infinite loop?
(I haven't found it explicitly on Maven's documentation nor googling it).

Why do the Sonatype docs suggest redefining the central repository with a bogus URL in settings.xml when using mirrorOf?

According to the Maven documentation:
You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with the Maven Repository Manager to proxy external requests.
To achieve this, set mirrorOf to *.
This StackOverflow question also suggests that setting mirrorOf is sufficient to block an external repository, so why does the Sonatype documentation suggest overloading central with an unreachable URL?
The bogus URL is really irrelevant - you can set it to the original one if you need to, or the URL of your repository manager - as long as the mirrorOf is applicable, it won't be used.
The reason these examples redefine central is to set policies on artifact requests to the default repositories. By default, Maven does not enable snapshot requests to central, and uses default update and checksum policies. Redeclaring central allows these to be overridden - in this case, to enable snapshot artifacts and plugins, and the mirror then redirects all of these to the repository manager. This avoids the need to declare the repositories in your POM (as long as all users have their settings correct).
I wrote that so I can tell you what I was thinking ;-)
The central repository definition needs to be updated to enable snapshot retrieval for at least one repo, otherwise Maven won't even ask the repository manager (pointed to by the mirrorOf) for any snapshots.
While not required, I like to change the definition of the url to be an invalid one also so if there is a misconfiguration somewhere else in the system, it becomes immediately obvious what is happening. Otherwise Maven may still reach out to Central and mask the problems. It's essentially a fail-fast setup.
There's more information on this topic in an old blog I wrote
maven needs project dependencies to be available locally for it to run. It does not care about how it is made available - whether manually installed (using mvn install:install-file), through a mirror or by from central repository. It will fail to run if it is unable to find dependencies.
The sonatype documentation that you are referring to is on using nexus to mirror/proxy repositories. The url specified should be a valid nexus url and cannot be unreachable.
The same is suggested in the SO question as well.

Resources