I want to use this android dependency in my java program:
http://jcenter.bintray.com/com/o3dr/android/dronekit-android/2.9.0/
so I added all the plugins & repositories into my maven pom file:
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.1.0</version>
<extensions>true</extensions>
<configuration>
<sign>
<debug>false</debug>
</sign>
</configuration>
</plugin>
...
Then I add the dependency into the same file:
<dependency>
<groupId>com.o3dr.android</groupId>
<artifactId>dronekit-android</artifactId>
<version>2.9.0</version>
<type>aar</type>
</dependency>
But nothing happens, maven ignore it as if it doesn't exist, if I import its main package in a scala file and build it with mvn clear install -U, I get this error:
[ERROR] /home/peng/git-drone/dronespike/src/main/scala/Main.scala:1: object o3dr is not a member of package com
[ERROR] import com.o3dr.android._
[ERROR] ^
Question: What should I do to fix this problem?
Use Android packaging, e.g. <packaging>apk</packaging>.
If Maven couldn't download the artifact, it would complain much sooner in the build lifecycle. The problem is that artifact is downloaded, but not used. aar is not a standard Maven artifact, so Maven doesn't know what to do with it. Using it requires a third party plugin with extensions, hence usage of android-maven-plugin. Reading its documentation, it has some requirements to work properly. Specifically you didn't use android packaging as mentioned here:
usage of a supported packaging: apk, aar or apklib
Indeed, looking at the plugin source code it checks for android packaging before adding anything from aar to classpath.
Depending on the requirement from your maven version, based on what I faced before, you might have the need to add the configuration for release and snapshot. In my case, I was just able to get the lib once I specified these parameters:
<repositories>
<repository>
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.o3dr.android</groupId>
<artifactId>dronekit-android</artifactId>
<version>2.9.0</version>
<type>aar</type>
</dependency>
</dependencies>
without it, the dependency was not downloaded.
Looking at the bintray repository from where the dependency is available, and check the repository settings via its Set me up option, your repositories coordinates are not correct, they should instead be:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-3d-robotics-maven</id>
<name>bintray</name>
<url>http://dl.bintray.com/3d-robotics/maven</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-3d-robotics-maven</id>
<name>bintray-plugins</name>
<url>http://dl.bintray.com/3d-robotics/maven</url>
</pluginRepository>
</pluginRepositories>
And indeed the effective target file is available via the URL:
https://dl.bintray.com/3d-robotics/maven/com/o3dr/android/dronekit-android/2.9.0/
Which respects the repository URL plus its Maven coordinates (groupId, artifactId, version).
Also note: do not reuse the repository id central, unless for specific reason, otherwise you would override the central (default) repository of your Maven build and all of your dependencies (and plugins) would only be fetched by the newely declared one.
sbt-android can handle this configuration.
build.sbt
androidBuildJar
name := "yourproject"
organization := "yourorganization"
platformTarget := "android-24"
libraryDependencies +="com.o3dr.android" % "dronekit-android" % "2.9.0"
project/plugins.sbt
addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.7")
Add publishing and resolver rules as necessary.
Related
I have a local Java intelli-J project with a pom.xml that has (2) internal repositories on artifactory. The problem is I am doing some testing, and I think one of the JARs is not on this internal repo, so I want to use the regular Maven central repo. I googled and believe, the artifact should go through the list in your pom.xml is the order its listed and try to resolve the artifact, the problem is, even when I add the Maven central repo, it seems to never attempt; only tries the internal artifactory then fails.
In my pom.xml:
<repositories>
<repository>
<id>test</id>
<name>Maven Central</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>my_repo</id>
<name>MyRepo</name>
<url>https://myinternalrepo.com</url>
</repository>
<repository>
<snapshots />
<id>MySnapShotRepo</id>
<name>MyInternalRepo</name>
<url>https://myinternalreposnapshots.com</url>
</repository>
</repositories>
am I doing something wrong here?
I removed my settings.xml and was able to control the repositories from the pom.xml file tag. It also looks like maven repo is automatically tried whether you list it or not in pom .
In my Maven configuration I have 6 repositories. 3 Open Source for Geo Tools Java framework and 3 proprietary with encrypted credential access.
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
I added the external repositories mentioned here: http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html
I added the plugin repositories as well and updated my settings.xml so the repositories in both matched.
<pluginRepository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</pluginRepository>
<pluginRepository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</pluginRepository>
<pluginRepository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</pluginRepository>
I even downloaded the jars I need for these Geo Tool dependencies and placed them in my .m2 folder.
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>18.2</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>18.2</version>
</dependency>
However, when I try and run a mvn clean install -X I can see that I am getting a 401 Unauthorized when Maven is trying to transfer org.geotools jars to/from the proprietary repositories I have configured, but I don't even want Maven to try.
How can I configure Maven so that for org.geotools.* load from these 3 repositories : <id>maven2-repository.dev.java.net</id>, <id>osgeo</id>, <id>boundless</id> and otherwise load from the proprietary repositories?
I heard that I can configure a proxy, but nobody is explaining how I would do that. I tried to store the jars I need for Geo Tools in my proprietary repository, but was told I can't. I also tried to configure a mirror to direct traffic to those external repositories only in my settings.xml like this below, but am seeing issues of cannot transfer jars from/to that only exist in the proprietary repository.
<mirrors>
<mirror>
<id>boundless</id>
<name>Boundless Repository Mirror</name>
<url>http://repo.boundlessgeo.com/main</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
I don't know if this can be done with maven but can be done with Artifactory virtual repositories. Other repository management tools should have similar concepts.
Basically you setup a Artifactory repository and your applications should refer to this repository. And you can configure inside Artifactory to which jars should be download from which repositories.
Consider that the Include Patterns and Exclude Patterns for a repository are as follows:
Include Patterns: org/apache/,com/acme/
Exclude Patterns: com/acme/exp-project/**
In this case, Artifactory will search the repository for org/apache/maven/parent/1/1.pom and com/acme/project-x/core/1.0/nit-1.0.jar but not for com/acme/exp-project/core/1.1/san-1.1.jar because com/acme/exp-project/** is specified as an Exclude pattern.
https://www.jfrog.com/confluence/display/RTF/Common+Settings#CommonSettings-Package
https://www.jfrog.com/confluence/display/RTF/Virtual+Repositories
Is it possible to add remote repository jar file (https://repo.ah/lib/abc.jar) in maven pom.xml as dependency in java project. if so, can you please share example.
No, it's not possible to add a complete repository as a dependency. This doesn't make sense, because a repository can contain ten thousands of artifacts.
If your project requires artifacts which are not hosted in the standard remote repository, you can specify this via the <repositories> tag in your pom.xml .
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More Informations:
Introduction to Repositories
Setting up Multiple Repositories
In the comments you mentioned that the URL is an Artifactory.
So just add the Artifactory as <repository> to your settings.xml and then you can use the jar in your application.
I want to use Sikulix in my maven project but it doesn't work, I tried to add the repository like it says (http://sikulix-2014.readthedocs.org/en/latest/faq/030-java-dev.html#a-comment-on-projects-using-maven) and when I do "mvn install" it says "Could not find artifact com.sikulix:sikulixapi:jar:1.1.0-SNAPSHOT in nexus" where nexus is our repository.
My pom contains that:
...
<repositories>
<repository>
<id>com.sikulix</id>
<name>com.sikulix</name>
<url>https://oss.sonatype.org/content/groups/public</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
...
Any idea why maven does not find the artifact in the correct repo?
The problem is solved. In the settings.xml we had a so maven always used the same repo.
I just removed the mirror because we didn't use it anymore, but I think that adding the additional repository there it would work too.
I want to add to my project some special dependeny from some repository.
For this I add the repository in my pom:
<repositories>
<repository>
<id>jenkins-repo</id>
<name>Jenkins Repository</name>
<url>maven.jenkins-ci.org/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
.. and in the same file add the dependency:
<dependency>
<groupId>org.jvnet.com4j</groupId>
<artifactId>com4j</artifactId>
<version>20120426-2</version>
</dependency>
But it doesn't work: the dependency is not found. As far as I understand this proves that the dependency exists in the right place:
http://maven.jenkins-ci.org/content/repositories/releases/org/jvnet/com4j/com4j/20120426-2/
So here are the questions:
1) Where I went wrong?
2) If I add repository to pom the default repository still be checked?
3) The link provided is really a link to Maven repo which proves I can download an artifact from it?
change <url> to include protocol
<url>http://maven.jenkins-ci.org/content/repositories/releases</url>