How to add dojo-maven dependency? - maven

I am currently trying to add dojo as maven dependency in a web project.
I found this link: http://mvnrepository.com/artifact/org.dojotoolkit/dojo-maven/1.8.0
where I copied the dependency node into my POM.
Next I searched where the dojo-maven artefact lies (in which repository). But I cannot find this information. I tried adding:
<repository>
<id>maven2repo</id>
<url>http://central.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
But when I build it sais: Could not find artifact org.dojotoolkit:dojo-maven:jar:1.8.0 in maven2repo (http://central.maven.org/maven2/)
The dojo-maven artefact can be found here http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22dojo-maven%22
Another place to search can be here http://download.dojotoolkit.org/ under the maven category.
Can someone give me a hint?

Do you have a dependency defined in your pom?
<dependency>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo</artifactId>
<version>1.8.0</version>
</dependency>
This will only add the "compiled" dojo code. It is not the full SDK (with the build utilities, etc). There is an outstanding ticket to publish the full SDK to the maven repository.
http://bugs.dojotoolkit.org/ticket/15120

Related

maven.elasticsearch.org returning a 404

We are running into an issue with our Maven dependency on the Elastic Search Libraries that our code depends on in order to build / compile.
The build process fetched these libraries at build time, however the maven elastic search repository seems to be off line all together.
http://maven.elasticsearch.org/ currently returns a 404 resulting in everything below it being unavailable which results in the build process failing.
Even the maven central repo for elastic shield returns 404's https://repo.maven.apache.org/maven2/org/elasticsearch/plugin/shield/
I have sent an email to support#elastic.co asking them to turn the Elastic Repo back on, any other idea why this repo would just go offline and how would I go about rectifying it? A local onsite mirror of central, but it feels like overkill for what we need it for.
From the official document here
The repository URL is : https://artifacts.elastic.co/maven/org/elasticsearch/plugin/shield/2.4.6/shield-2.4.6.jar
If you are using maven:
<project ...>
<repositories>
<!-- add the elasticsearch repo -->
<repository>
<id>elasticsearch-releases</id>
<url>https://artifacts.elastic.co/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
...
</repositories>
...
<dependencies>
<!-- add the shield jar as a dependency -->
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>shield</artifactId>
<version>2.4.6</version>
</dependency>
...
</dependencies>
...
</project>

How to add more sources for Find Jar on Web in IntelliJ

When I right-click a missing import, I have an option of "Find Jar on Web", but the Jars in the list are outdated. For example, the newest ant jar on the list is ant-1.7.1.jar, but I know that ant-1.10.1.jar is available from Maven Central.
How can I add more "sources" to the search of IntelliJ?
This happens because the repositories is outdated in your IntelliJ, so, you can update with these steps, go to:
Preferences > Build, Execution, Deployment > Maven > Repositories
Choose the Remote repository entry and click on Update button, this action takes some minutes, after of that, do the same with your Local repository, IntelliJ will be able to retrieve the last versions of your dependencies.
UPDATE
To view the remote repositories in IntelliJ, you can add in your settings.xml file (check this) or directly in your pom.xml file of your project.
This is the structure for your settings.xml file:
<project>
<repositories>
<repository>
<id>maven-central</id>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
</project>
And this is the structure for your pom.xml file:
<dependencies>
...
</dependencies>
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://repo.maven.apache.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
After of add this configuration, IntelliJ will be able to detect the new repository.
Notice: The updated specified in your pom.xml file (or inherited from parent project's pom and settings.xml)

Maven Settings.xml Add Multiple Servers With Priority

My work has its own maven server that it uses. Unfortunately, when I try to add a dependency to http://mvnrepository.com/artifact/commons-dbutils/commons-dbutils/1.6 it is not being found.
My question is how do I modify my settings.xml to allow for a 2nd server, which would be the mvnrepository, but only reference that server if the dependency isn't found on the main server?
Doing some search on stack overflow, I found the following answer to be useful: Do you know the maven profile for mvnrepository.com?
I did a combination of Tristan and Nicolas' answers, which let me add the following into my settings.xml:
<repository>
<id>maven repo</id>
<url>http://central.maven.org/maven2/</url>
<snapshots>
<enabled>false</endabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
Closed my project, reopened then reimported the maven dependences and all was good.

How maven handle multiple <repository> configurations?

I am getting more and more comfortable with maven. But still some questions.
I have multiple <repository> in my pom.xml.
How will maven handle these repos when downloading artifacts? Will it search by the declaration order?
Besides the explicitly declared ones, will maven still check the default central repo at http://repo.maven.apache.org/maven2/?
If something cannot be found within the explicitly configured repo, will maven fallback to the default central repo?
Is it good to use multiple repos? I am kind of worried about inconsistency.
Below is the <repositories> section of my pom.xml:
<repositories>
<repository>
<id>ibiblio-central-repo</id>
<layout>default</layout>
<name>ibiblio-central-repo</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.ibiblio.org/maven2/</url>
</repository>
<repository>
<id>oschina-central-repo</id>
<layout>default</layout>
<name>oschina-central-repo</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.oschina.net/content/groups/public/</url>
</repository>
<repository>
<id>oschina-central-repo-3rd-party</id>
<layout>default</layout>
<name>oschina-central-repo-3rd-party</name>
<releases>
<checksumPolicy>warn</checksumPolicy>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
</repository>
</repositories>
How will maven handle these repos when downloading artifacts? Will it
search by the declaration order?
Order of declaration as part of the merged settings (see next answer). I have found this JIRA ticket providing further details.
Besides the explicitly declared ones, will maven still check the
default central repo at http://repo.maven.apache.org/maven2/?
Yes, as it will be provided by the Maven super POM, implicit parent of all Maven Pom (here an official example), unless specified in your settings.xml (if you override the repository id specified in the super POM). You can use the Maven Help Plugin to get the effective settings Maven will apply to your build and the effective pom maven will actually (effectively) run.
As documented here, the repositories element is inherited.
If something cannot be found within the explicitly configured repo,
will maven fallback to the default central repo?
As above. Moreover, you could also influence this mechanism via any configured Maven mirror. You could, for instance, redirect Maven to your company repository (see below) instead of looking up on the default one.
Is it good to use multiple repos? I am kind of worried about
inconsistency.
You probably don't need many configured repositories, but you might need more than one if the dependencies you are looking for are not provided by the default repository. A good approach would be to have an enterprise Maven repository (i.e. Artifactory, Nexus) and make your local settings only point to it. Then, configure the internal Maven repository to point to other repositories, in a centralized (and governed) manner.

Why is maven looking for artifact in the wrong repo?

I'm defining a dependency in pom.xml in a Maven 3 project. Dependency is as follows:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<scope>runtime</scope>
<version>2.2</version>
</dependency>
Repostory is described in pom as follows:
<repository>
<id>java.net</id>
<name>java.net</name>
<url>http://download.java.net/maven/2</url>
</repository>
Artifact is indeed present in the repository. It's easy to check. Despite that, Maven is trying to obtain the artifact from repo1.maven.org. What could be the reason of this? Maybe I make some crucial mistake in defining repository access? Other dependencies seem to do fine.
Plugin org.mortbay.jetty:maven-jetty-plugin:6.1.26 or one of its
dependencies could not be resolved: Could not find artifact
org.glassfish.web:el-impl:jar:2.2
in central (http://repo1.maven.org/maven2)
The repository that you have defined is used for dependencies, but not for plugins. Hence the error.
To address this, you need to define pluginRepositories:
<project>
<!-- ... -->
<pluginRepositories>
<pluginRepository>
<id>{repo.id}</id>
<url>{repo.url}</url>
</pluginRepository>
</pluginRepositories>
</project>
As to where you should specify - in pom.xml or settings.xml, read this SO post.
You need to check your maven settings.xml (Look into Maven folder: M2_HOME/conf).
The default repositories are defined there itself, and Maven central repository is taking precedence.
Define your repository in Maven's settings.xml like this:
<profiles>
<profile>
...
<repositories>
<repository>
<id>Java Net</id>
<name>Java Net</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</profile>
You can maybe overwrite the default Maven central repository location with yours if you don't want to do much configuration.
Cheers!
In my case, the real root issue was that the repo required authentication. However for some reason maven decided that it would be much better to not tell me that, and to instead use the first repo in the <repositories> list, and throw the Could not find artifact error for that repo.
After moving the repo that contained the package so it was the first one in the <repositories> list, it started showing me a "permission denied" message. Once maven was setup for authentication with the repo in question, the issue went away.
I had a similar problem however, another developer had set up a mirror in that I simply copy-pasted into my settings.xml file. Modifying the mirrorOf property to only include specific repos did the trick.
In addition to the above mentioned answers, make sure your settings.xml is saved as an xml file not a text file i.e. its not saved settings.xml.txt.

Resources