Missing of added jars to maven builth classpath via static in-project repository solution - maven

One of the best strategies recommended for adding of JARs files in maven's project with no public repository is using of static in-project repository. Nice blog : http://charlie.cu.cc/2012/06/how-add-external-libraries-maven/ or one of the most popular as I found StackOverflow posts Can I add jars to maven 2 build classpath without installing them?
Does someone have had next issue when make totally same steps for integrating of the solution (my particular case is adding of filters-1.0.jar file): "Missing artifact imageUtil:filters:jar:0.1:compile" or in other words, nevertheless the static in-project repository is set up in pom.xml at the end also could not be recognized ? Does something is missed by me ?
Here are my steps integrating of the solution:
create a "repo" folder in root of my maven project
in pom.xml I registered static in-repository :
<repository>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/repo</url>
</repository>
Again in pom.xml added mention dependency :
<dependency>
<groupId>imageUtil</groupId>
<artifactId>filters</artifactId>
<version>0.1</version>
</dependency>
last step is copy-pacing of mention JAR in next sub-folder structure
/repo/imageUtil/filters/0.1/filters-0.1.jar
When I checked in buildpath for the project (I am using Eclipse) I also saw that mention JAR is looking in my local repository or
- /home/simeon/.m2/repository/imageUtil/filters/0.1 (missing)
Maybe the question here is "how to say to my maven project that this JAR should be searched in my static in-project repository" ?
Thanks in advance,
SImeon

Your settings look fine. Is it never taking your in-project repository or do you mean it works first time and after that it will look only in the /home/simeon/.m2/repository/imageUtil/filters/0.1
I tried something similar and saw that if I give the name of a standard library which is available in a Maven Central repository, it looks there first and downloads it from there.
So I took a standard library (saxon) and renamed it to something different (eg: saxonic) which I know will not be available in any external repo, and I can see it uses my defined "inprojrepo" and installs this into my own local maven repository.
After that it uses from the local maven repository for next build.
[INFO] ------------------------------------------------------------------------
Downloading: file://D:\mymavenproject\someproject/inprojrepo/net/sf/Saxo
nic/9.4/Saxonic-9.4.pom
Downloading: http://repo.maven.apache.org/maven2/net/sf/Saxonic/9.4/Saxonic-9.4.
pom
[WARNING] The POM for net.sf:Saxonic:jar:9.4 is missing, no dependency informati
on available
Downloading: file://D:\mymavenproject\someproject/inprojrepo/net/sf/Saxo
nic/9.4/Saxonic-9.4.jar
Downloaded: file://D:\mymavenproject\someproject/inprojrepo/net/sf/Saxon
ic/9.4/Saxonic-9.4.jar (9560 KB at 29234.1 KB/sec)
[INFO]
My POM
<repository>
<id>inprojrepo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/inprojrepo</url>
</repository>

Related

How Maven project downloads dependencies from Maven central?

Have a few Maven projects in our environment, and currently it is downloading the required dependencies mentioned in the pom.xml file from Maven central.
I was trying to figure out where the URL for Maven central is provided in pom file or project level, and unable to find out. I thought it could be in settings.xml, and found the below script:
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
Can someone provide inputs on the details of providing the Maven central URL in project/pom file level or where do we mention it ?
Thanks !
It is defined by maven core, more accurate in maven-model-builder (so called super pom).
If you like to change that which means usually to redirect everything via an internal repository manager the way to go is via the user settings.xml see for details: https://maven.apache.org/settings.html
The user settings is located in users home directory $HOME/.m2/settings.xml.
You should prevent to define repositories in pom.xml files, because it happens that the location of such repositories (repo managers) may change which would result in pom.xml which can not being built anymore after a time.

maven goal using default maven repo and not the configured one

I am trying to integrate evosuite in my maven project using instructions from here and here.
I can build the project (clean install) without any issue.
I can execute evosuite:help or evosuite:prepare goal without any issue.
However I am having issue with evosuite:generate goal. There is problem downloading the transitive dependency.
We are using our own central repository which have all the jars that evosuite or evosuite plugin needs yet I can see in the logs that evosuite:generate goal tries to connect to default maven central repo (repo.maven.apache.org)
instead of the repo that I have configured.
For example;
I have following configuration in my paren pom :
<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
So when I execute clean install, it downloads jars from jcenter.bintray.com
Downloading: http://jcenter.bintray.com/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: http://jcenter.bintray.com/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 3.1 KB/sec)
Downloading: http://jcenter.bintray.com/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
Downloaded: http://jcenter.bintray.com/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 20.7 KB/sec)
But while execute evosuite:generate it downloads some artifacts from repo.maven
Why is that? How can I force it to refer our custom repo (jcenter in above example)
Here is complete logs for same.
Executing in debug mode, I saw a warning that
The pom for <name> is invalid, transitive dependencies (if any) will not be available
I have deleted the .m2 folder, checked the jars, downloaded the jars manually and refer them via local url in pom. But it did not solve the issue.
The goals executes fine when you execute from an environment where there are no proxies or other network restriction.
Hence I believe If I am able to use our repo instead of maven default one when goal evosuite:generate executes, I might be able to solve the issue.
Note: I dont think there's any issue with setting.xml
It has all the configuration for proxy and to use our own artifactory.

Maven: Error resolving version for plugin

I am trying to get Batik working, having not worked with Java much in the last ten years or so and I'm running into problems with Maven being able to find the org.apache.maven.wagon:wagon-ssh-external package.
When I open or try to build the project in Netbeans, it reports the following error:
The project org.freehep:freehep-graphicsio:2.1.1 (/home/glenatron/Projects/batik/freehep-graphicsio/pom.xml) has 1 error
Unresolveable build extension:
Error resolving version for plugin 'org.apache.maven.wagon:wagon-ssh-external' from the repositories [local (/home/glenatron/.m2/repository), freehep-maven (http://java.freehep.org/maven2), central (http://www.ibiblio.org/maven2), Codehaus (http://repository.codehaus.org/), Codehaus Snapshots (http://snapshots.repository.codehaus.org/)]:
Plugin not found in any plugin repository -> [Help 2]
As far as I can tell this is correct, however, I have the following in my pom.xml file for the project:
<repositories>
<repository>
<id>freehep-maven</id>
<name>Maven FreeHEP</name>
<url>http://java.freehep.org/maven2</url>
</repository>
<repository>
<id>maven-apache</id>
<name>Maven Apache</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>maven1</id>
<name>Maven.org</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
From what I can judge a) that plugin should be available in one of those repositories and b) if they are in the pom.xml file, Maven should be searching them but I can't see any sign of it doing that.
The project I am trying to work with is the FreeHEP EMF driver. The bigger screen solution was to use the unsignposted but much more up to date Github repository version.
It turns out that the solution was in the message after all: Error resolving version for plugin.
So obviously it's not a repository it is a pluginRepository which goes in a different part of pom.xml:
<pluginRepositories>
<pluginRepository>
<id>maven1</id>
<name>Maven.org</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
Remove the entries with repo1... cause this is maven Central and used by Maven by default so no need to define it explicit. Furthermore the given freehep.org is also available via Maven Central. So if i see it correct you don't need to define supplemental repositories at all.

Installing a maven project with a dependency on a parent

I have a collection of related projects that inherit from a common maven project.
Since they are still in alpha release, they all (including the parent) are deployed in the Sonatype snapshots repository, instead of Maven central.
The configuration for accessing the maven central is in the parent project of my application.
So its POM specifies as its parent:
...
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
...
And set the corresponding repository at Sonatype:
...
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
...
So the children projects do not have to repeat this configuration.
The parent also provides many other things that are common to all my projects.
Currently I keep all these projects in unrelated directories.
Now, if a user of my application checkout one of my projects and attempt to install it with mvn install, he will receive the error: Non-resolvable parent POM: Could not find artifact ...
This makes sense to me, since the project cannot access the Sonatype repository (e.g., for downloading the parent) since it is precisely the parent the one that contains how to connect to such repository.
I do not want to request the user to install first the parent project, since he should be able to install what he needs in just one single step.
Then what is the recommended way to distribute my libraries so the user can install any of them with one single command ?
It occurs to me that I could include the parent POM in each of the projects (for example, using git submodules) so the parent can be resolved locally. But I am wondering if this is the best way to organize this (?). Any better alternative is appreciated.
UPDATE
I added this to my ~/.m2/settings.xml so the parent POM could be resolved in the Sonatype snapshots repository. Apparently it is working fine and the parent POM is resolved as any other dependency.
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
If you want to keep it to one step install than you have to list enough information in the project pom, i.e. either:
no parent pom, put all the information into each project pom
tell maven where to find your other projects. List the sonatype shnapshot repo in each project file.
A repository manager only helps those with access to it. That is ok if the users are in one organisation. Using the sonatype repository reaches a wider circle.

Deploying Java Application to Heroku Results in jackson-mapper-asl Maven Error

The exact maven error message when deploying to heroku is:
No versions available for org.codehaus.jackson:jackson-mapper-asl:jar:[1.9,1.9.9] within specified range
I believe the issue is related to this answer and this Jackson repository maven-metadata.xml bug.
The following entry in the maven deploy log indicates that jackson-mapper-asl 1.9.9 is being downloaded from a heroku maven repository:
Downloaded: http://s3pository.heroku.com/jvm/org/codehaus/jackson/jackson-mapper-asl/1.9.9/jackson-mapper-asl-1.9.9.pom (2 KB at 12.3 KB/sec)
The heroku versions of the jackson maven-metadata.xml files are using incorrect version numbers - causing the maven error when using version ranges.
Is there a way, at deployment, to tell heroku to use a different maven repository for this dependency? Better yet, is there a way to get the heroku jackson-mapper-asl maven-metadata.xml file fixed?
Could this suffice as a workaround? You could just take the repository configuration section and point to somewhere else or supplying the file yourself as you would do with custom items.
Anyway, you can do it. Defining a regular repository in pom.xml, here the central one:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Defining a repository in pom.xml that is pointing to a local "repo" item, which exists only within the application deployment:
<repositories>
<!--other repositories if any-->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>
You should contact Heroku support about this in any case.
Follow Up I contacted Heroku support (super helpful, BTW) and they discovered the Heroku Maven cache was invalid for more than just Jackson. Heroku support kicked off an update process that helped resolve the problem but did not fix it completely. To get this issue completely resolved I had to add an explicit dependency to jackson-mapper-asl 1.9.9 in my pom.xml before I could deploy my app to Heroku.

Resources