I am working on a Java project, using maven as our dependency manager/build tool. I am currently having a problem resolving a dependency's dependency to the correct version.
The dependency in question is called jasperreports-functions-6.1.0.jar which is not hosted in a maven repo but provided in jar form.
The problem I'm having is that jasperreports-functions needs commons-lang 2.6. Inconveniently, during "compile" Maven itself builds commons-lang 2.1 to create the reduced-pom. It seems this leads to jasperreports-functions trying to use commons-lang 2.1 because it is available, but this is not valid (method undefined errors at runtime.)
I have tried adding commons-lang 2.6 as a dependency but still it seems jasperreports-functions is using the 2.1 version.
pom.xml snip:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-functions</artifactId>
<version>6.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jasperreports-functions-6.1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Using "mvn dependency:tree" I can see that no dependency requires commons-lang.
If I delete 2.1 from ".m2\repository\commons-lang\commons-lang" it gets recreated by maven. If I empty the folder and lock the permissions on it, then run maven again I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project JavaLibrary: Execution default-jar of goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar failed: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-jar-plugin:jar:2.4 -> commons-lang:commons-lang:jar:2.1: Failed to read artifact descriptor for commons-lang:commons-lang:jar:2.1: Could not transfer artifact commons-lang:commons-lang:pom:2.1 from/to central (https://repo.maven.apache.org/maven2): C:\Users\Lowell\.m2\repository\commons-lang\commons-lang\2.1\commons-lang-2.1.pom.part.lock (Access is denied) -> [Help 1]
How can I force the jar dependency to use a certain version of a sub-dependency?
Have you tried to reorder the depency entries,
first to load commons-lang then to load jasperreports ?
Edit:
Maybe this should help you: dependency:analyze-dep-mgt
What you are doing should be enough. The newer version should override the older version AND the version you specify explicitly should override any transient dependency. I believe Maven 2.x had problems in this area which is why I updated to Maven 3.x
I suspect the problem is somewhere else. I suggest trying to delete common-lang 2.1 and I suspect this should show you what the real problem is.
Try this:
1> Maven clean.
2> Right click on project->maven -> update project configuration - > force update
Related
I have a problem when building a default project created by NetBeans when Maven-Java Web application is created. When I add Spring MVC dependency under Properties->Framework category and build a project I get this error:
Failure to find org.springframework:spring-framework-bom:jar:4.0.1.RELEASE in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
You have a placeholder in your local repo, try to delete this placeholder
delete the folder
~/.m2/repository/org/springframework/spring-framework-bom/4.0.1.RELEASE
Then rebuild with
mvn clean install -U
This assume your maven instillation is correct.
Did you add this dependency?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.1.RELEASE</version>
<type>pom</type>
</dependency>
and throws you that error? Could be a missed library.
Before adding it manually (or any other solution), make sure u really need the spring bom in your dependencies...
The bom should go under dependencyManagement section in your parent pom xml.
BTW the bom is only available as "POM" , not as "jar" scope.
I am trying out Apache Spark and have a little problem that I am stuck with. I have this JavaSparkHiveExample.java example from the Apache Spark Github together with a pom.xml that I have created as a Maven project in IntelliJ IDEA.
I am able to run other Spark examples (using another simpler POM) but this one is giving me the following errors:
Scala is installed in Idea
I am new with Maven and would therefore appreciate some things I could try in order to solve this problem.
Issue is with the value of $project.version. It is referring to your project' version (2.3.0-snapshot). There isn't any maven dependency with this version in Maven central repository, hence you are facing this issue. Instead of using the project version, you can add a new property like this and refer it for all dependency version
<properties>
<spark.version>1.6.2</spark.version>
</properties>
and then use it in the dependency
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
</dependency>
Make sure the version you are using is available in maven repository
https://mvnrepository.com/
I am new to Maven Project. I am making changes to one of the open source maven project. I am facing a problem in adding a library to the project. So far i have done this :-
I added a library named jni4net.j-0.8.8.0.jar to the resources folder of the project.
I right clicked the jar(in Intellij) and clicked 'Add as library'.
Then in the pom.xml i added:-
<dependency>
<groupId>jar.0.8.8.0.jni4net</groupId>
<artifactId>jar.0.8.8.0.jni4net</artifactId>
<version>0.8.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/jni4net.j-
0.8.8.0.jar</systemPath>
</dependency>
But when i build this project(build is successful, test cases are running) and use this it throws following error:-
java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
Please help me resolve it. I am new to maven and pom. I have looked at various answers, but not getting it right.
PS - I named groupId and artifactID as just reverse of jar file
This is not the right way to add that dependency.
All you need is:
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
The dependency will be retrieved from Maven Central when you build.
Using <systemPath>...</systemPath> is highly discouraged as it usually ties your project to a local environment.
Since jni4net.j dependency is available in maven central, You don't have to download and put the dependency manually. Maven will download and store the dependency locally in `'.m2' folder. Just add dependency as bellow.
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
I couldn't find the spring-ldap jar in central maven starting from version 1.3.2.
We use maven to manage dependency and we pull the spring jars from central maven (in turn using an internal repository)because this jar is not available in central maven we are not able to pull it. Please advice why this jar is missing in Maven central and what alternate options are available?
Even in spring repo(https://repo.spring.io/release) the artifact are provided as a zip file and the jar isn't provided directly.
Looking for the below artifact
Group ID: org.springframework.ldap
Artifact ID: spring-ldap
version: 2.0.2
The best option, as for me, is to use needed submodules of spring-ldap, for instance spring-ldap-core:
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
I have to write a plug-in for Atlassian Confluence by using Atlassian SDK and and Java's SDK v8 on Eclipse IDE. Apache Maven (3.2.1) comes with Atlassian SDK which I have to use it from there (because there are a couple of dependencies that are shipped with the sdk that are not available in a maven repository); so I set the environment variables to point in there. Although, the POM file that I have to use comes with errors.
For example:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version> <!-- 2.2.2 -->
</dependency>
<dependency>
<groupId>com.atlassian.confluence</groupId>
<artifactId>confluence</artifactId>
<version>${confluence.version}</version>
</dependency>
On both dependencies it says, missing artifact, e.g.,
Missing artifact com.atlassian.confluence:confluence:jar:5.8.10
Although, in both cases, for example:
com.google.code.gson
the jar file at m2 actualy exists, yet the error at the POM file notifies that the artifact is missing.
I tried the atlas-mvn clean package, even after wiping the m2 repository explicitelly, and rerunning that command though it did not resolve the problems.
Did any body come across such a problem?
I needed to take each the *.repositories file under specific artifact dir (which causes problems), and perform following modifications, for example:
maven-confluence-plugin-6.2.2.jar>atlassian-public=
Needs to appear in the following format:
maven-confluence-plugin-6.2.2.jar>=
And it's done!