I want to use the commons-lang by maven,but apache repository isn't ,I down commons-lang-src publish in local repository ,but is warning.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test (default-test) on project commons-lang: There are test failures.
how to solve?
This is not the way to do it. As you can see in this maven mirror listing, the commons/lang sources are already available in all maven repositories that mirror central, so there is no need to build them yourself (BTW: if you build the project, you are installing the compiled binaries, not the sources, so even a success wouldn't have helped you).
Here's how to do it (Assuming you use eclipse):
If you use m2eclipse, just right-click the project and select Maven -> Download Sources
If you use the maven-eclipse-plugin see the page about adding sources to libs
If you don't use eclipse, I know there are similar plugins for NetBeans and IntelliJ Idea.
There are commons-lang binaries at repo1.maven.org.
http://repo1.maven.org/maven2/commons-lang/commons-lang/
Why don't use this?
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
Hope this will help you.
As an addition to #seanizer's answer, the command line solution is to use dependency:sources goal from the Maven Dependency Plugin:
dependency:sources tells Maven to resolve all dependencies and their source attachments, and displays the version.
So just run the following against your project on the command line
mvn dependency:sources
And maven will download the sources of dependencies, if they exist.
Related
I downloaded old project, which based on Eclipse, Ant or something else, I don't know this build system (I use Maven\Gradle). Project sources was converted to Maven manually, but project had more jar libraries. They were imported in project with help of IDEA (Project Structure -> Modules -> Dependencies), but libraries defined only in .iml file.
When I tried to build project in .jar with help of Maven — Maven show errors, that it cannot find classes from libraries (but in sources all good). I found in Internet example, like in this code sample:
<dependency>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>examle</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/example.jar</systemPath>
</dependency>
But this don't help. Libraries are old too, and they created by old build tools, which don't write artifact id, group id and etc., so I don't know this information.
How I can write dependencies on local .jar libraries in pom.xml if I don't know information (group, artifact ids) about they?
UPD_0:
When I try to set only system path to library, I take this:
All you need is set correct path in the
<systemPath>${project.basedir}/libs/example.jar</systemPath>
group, artifact ids and version are user defined information. So you can define it as you wish.
Try to install this jar in ur local repository from command line / terminal like this. Then add the dependency with the package and version given by you in the command without scope as system
mvn install:install-file -Dfile=<path>/example.jar
-DgroupId=com.something
-DartifactId=example
-Dversion=<give some version>
-Dpackaging=jar
-DgeneratePom=true
IntelliJ Maven pom.xml I get the following message:
Dependency org.xerial:sqlite-jdbc:3.8.11.1 not found.
How can I fix my problem? This is the only dependency in my pom.xml which doesn't work.
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.1</version>
</dependency>
after testing in a new Maven Test Project, it works now in my main projec. Thank
Check correctness artifact properties as group artifact and version, if they correct this mean your artifact is not in maven central repo you need manually add new repository in you pom.xml where this artifact present. If you artifact in maven central try to load them manually if you use maven not bundled in intellij install
-> open console in idea with alt + f12 then type mvn dependency:resolve
update
your artifact in central repo, https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.8.11.1
Sometimes i meet this bug in Idea (Idea does not see this dependency because it does not indexed by Idea or something like this, version of artifact highlight red but it is only idea deal) add manually this dependency or try to recheck (clear caches) and all will be work.
i'm kinda new to maven after coming from a simple yet uncouth ant world.
<dependencies>
<dependency>
<groupId>com.foo.bar.EPT</groupId>
<artifactId>EPTUtils</artifactId>
<version>1.2.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
I'm looking for a maven command to specifically update this version to 1.2.14-SNAPSHOT. I've tried
mvn -DallowSnapshots=true versions:use-latest-snapshots -Dincludes=com.foo.bar.*
but that didn't update what i had in my local repo.
Change
<version>1.2.9-SNAPSHOT</version>
to
<version>1.2.14-SNAPSHOT</version>
in the pom.xml of your Maven project. Then build the project.
mvn clean test package
Maven will download the dependency and store it in your local ~/.m2 repository.
Edit: Also see How do I tell Maven to use the latest version of a dependency? for more information about Maven and latest versions.
Edit 2: You can use the Versions Maven Plugin that as goals that can help you with that.
I'm merging two projects into one(mergin project1 into project2). Now I'm going to copy all dependencies from project1 pom into project2 pom, like :
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
</dependency>
And some others. The build is successful the thing in eclipse annoys me so much like when hovering over import org.apache.commons.configuration.ConfigurationException:
The import org.apache.commons.configuration cannot be resolved
But the build still succeds, what can I do to get rid of these?
If you use m2eclipse, you need to click Maven -> Update Dependencies.
Otherwise I guess you need to regenerate the Eclipse project with mvn eclipse:eclipse.
Try doing 'mvn eclipse:clean eclipse:eclipse'. That will force maven to delete all of the old eclipse configurations for your project and rebuild them from scratch.
Maybe try to edit POM by inserting whitespace and saving it. It should trigger rebuilding of the project. There is also a "Refresh Dependencies" option in m2eclipse plugin.
I had similiar problems when I used Eclipse integrated with Maven and the 1st technique usually helped.
Make sure a build is done successfully and ensure that on your Package Explorer the org.apache.commons jar is found under the Maven Dependencies section (given you have m2eclipse plugin installed in your eclipse)
What version of Eclipse, mvn and m2eclipse? Might want to double-check those.
You shouldn't need to do mvn eclipse:eclipse anymore - that's obsolete. You can try deleting your Eclipse project files and reopening the project (settings, project, classpath).
How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)