Reputation: 157
I imported the following package:
import org.apache.commons.lang.ArrayUtils;
I added therefore this dependency in my POM:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
Then my Maven build fails and this is my error message in Jenkins:
11:07:45 INFO: [INFO] 2 errors
11:07:45 INFO: [INFO] BUILD FAILURE
11:07:45 INFO: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project stripe: Compilation failure: Compilation failure:
11:07:45 INFO: [ERROR] /mnt/jenkinsSlaveWorkspace/xmakeProdSlave/workspace/somepath/util/MappingHelper.java:[7,32] package org.apache.commons.lang3 does not exist
11:07:45 INFO: [ERROR] /mnt/jenkinsSlaveWorkspace/xmakeProdSlave/workspace/somepath/gen/tmp/src/src/main/java/somepath/util/MappingHelper.java:[25,37] cannot find symbol
11:07:45 INFO: [ERROR] symbol: variable ArrayUtils
11:07:45 INFO: [ERROR] location: class
I read about something that I might have the wrong version or a version which is in conflict because of the version that is downloaded, so I tried 3.0, 2.6 and at the end 2.4 but nothing helped. I found a question here on StackOverflow some years ago and they talked about doing some commands in Maven. The point is I'm using a Maven plugin in Eclipse so I couldn't use the advice that was made there, anyone having the same problem?
Upvotes: 1
Views: 2042
Reputation: 3201
If your import statement is exactly as you pasted above, then use this dependency:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
However, if you wish to use commons-lang
's latest version, the import has to be:
import org.apache.commons.lang3.ArrayUtils;
And the latest dependency for this is:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
Background: Since version 3, commons-lang
depends on Java 5 (or later) and broke backwards compatibility. Consequently, the project renamed all the packages so that legacy code wouldn't stop working while enabling developers to use the added capabilities side-by-side. At the same time, the project decided to adapt the maven coordinates to the conventions.
Read more here: What's new in Commons Lang 3.0?
Upvotes: 2
Reputation: 2423
The shown dependency would be correct for the shown import
. Of course, except the fact that it is defined twice.
However, the compiler error relates to another import
, concretely from package org.apache.commons.lang3
. That particular import needs different dependency definition.
The commons-lang version with <artifactId>commons-lang3</artifactId>
has slightly different API - using JDK 1.5 features such as generics and varargs - and the Apache developers renamed the package
and the <artifactId>
in order to not to break existing code relying on the old API.
Upvotes: 0
Reputation: 357
It seems like the artifact has been moved to a different repo here. The maven dependency for that is:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
Additionally, if you need to execute specific goals, right click on your project in eclipse, mouseover "Run as" and click "Maven Build...". In the 'goals' field, you can enter the goals you saw in older posts. You could try 'clean install -U' to remove old stuff, install new dependencies and the last one to force an update.
Upvotes: 2
Reputation: 19
I think that you are a bit confused with maven imports. Why do you have imported two times the same thing?
Imports of dependencies needs to be in the bracklets
Try to import this:
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
EDIT: and you have groupId equals to artifact id and this is surely wrong!
Upvotes: -1