I have the following dependency in my gradle file.
compile 'org.A:A:1.0'
which automatically pulls in
'org.B:B:1.0'
and many other jars which it depends on.
But,my project requires repackaged A.jar (let's call it A*.jar which I installed in a local maven repository as custom version).
So now I change the dependency as below
compile 'org.A:A:custom'
which doesn't pull in any of the dependencies mentioned in the pom.xml file present inside the A.
jar file (which it would, had it been org.A:A:1.0)
My questions are:
1) Based on what does the statement compile org.A:A:1.0 pull other jars ? Is it pom.xml file present inside the jar?
2) What are the changes required if I want to automatically pull in both 'org.B:B:custom' and regular versions of other jars which are dependee of org.A:A:1.0
Maven will read the pom file for the artifact it resolves as well. In there the dependencies are found and resolved.
You simply need to also upload the pom of A*.jar and modify the version of it accordingly to A* - that should already do the trick.
Related
Update
I would like to use external library that is not available on maven repository.
Currently, I have subproject called libs and within CLIPSJNI.jar
In Gradle.build of root project I declare dependency like this
dependencies {
implementation files('/libs/library.jar')
}
but in order to run java application I also have to add file with .jnilib.
My question is it possible to publish to maven local this jar and reuse this dependency. So that .jnilib is redundant.
Initial question was resolve. If you wanna use CLIPSJNI in java application there are only 2 steps you should follow, which are described in comments down below.
I am working on a multi-module maven project and have third party jar which isn't available in central or public repository, I also even don't want to place on public repo. I am providing following plugin directive in my parent pom to install jar in my local maven repository before its dependency is resolved in child project.
Now I provide dependency in child project as;
But I build the project, it successfully adds dependency in local maven repository (places third party jar in .m2 folder) but the at the same time it gives following error. Looks like, it searches this jar file in child projects libs folder as well, while I have already placed it on root (in myproject.parent/libs).
Failed to execute goal org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file (install-
external-non-maven1-jar) on project myProject.core: The specified file 'C:\Users\myuser\git\MyProjectRepository\myproject.parent\myproject.core\libs\be-ixf-java-sdk-jar-with-dependencies.jar' not exists.
I already know scope and systemPath option but I don't want to use it for some reason.
Kindly help in identifying what I am missing ?
The best approach that you could have if your project have a centralized maven repo like nexus setup is to have your third party library also added to the repo. Now , you are having the bin file added to your project and it's not preferable.
If you already have the required jar under your project code in like : libs\*, then why can't you refer the dependency directly in your pom.xml instead of having to install it in your local maven repo and then use it .
<dependency>
<groupId>anything</groupId>
<artifactId>anything</artifactId>
<version>anything</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jar_name.jar</systemPath>
</dependency>
providing the location of the dependency in your project directory should resolve it during build itself.Look at Maven System dependencies.
Since you do not want to change your current setup . Please bear in mind the following about maven pom structure :
Project Aggregation is similar to Project Inheritance. But instead of
specifying the parent POM from the module, it specifies the modules
from the parent POM. By doing so, the parent project now knows its
modules, and if a Maven command is invoked against the parent project,
that Maven command will then be executed to the parent's modules as
well
So the maven-install-plugin execution that you added in main pom.xml might be getting triggered for all your modules because of this reason. You might want to move that to the module that you actually need this lib to be included in.Read maven doc.
Related : force Maven to copy dependencies into target/lib
When creating an artifact in IntelliJ IDEA and adding dependencies to my pom.xml, the artifact dependencies are not updated. If I then export the JAR file using my artifact configuration assuming everything is fine, I will get a class not found exception since the dependencies were not fully exported.
Is there a way to make IntelliJ automatically use all dependencies for exporting? I understand that this is not always desired behavior when using multiple artifacts (to cut down on the file size) but mostly when only using one artifact it is preferred to not having to delete and recreate the artifact configuration frequently.
This looks like a job for Shade plugin
Just import jar manually to project library
Project>Open Module Setting >Libraries>"+" sign in middle tab ( add new project library - from Maven) > type Your file and add it
I am working in a Maven project which has about 250 jar dependencies. Approximately Four out of five dependecies are not direct dependencies, I mean, they are dependencies of our dependencies (i.e jasperreport has about 8 dependencies).
Also, I suspect that there are some jar which we don't need to the project because they were old dependencies of old tool that we needed in the past but they were replaced by others.
What I need is:
To detect what jars of my pom.xml are not needed by the
project.
A way of removing the indirect jars from my pom.xml.
*Note: I'd swear that some time ago I manage to the indirect jars were downloaded by the direct dependencias, but I can't find how.
You're after mvn dependency:analyze:
Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused and declared.
This will let you remove any dependency which is not directly used from your pom. The dependencies that are used will still bring in their transitive (indirect) dependencies, as required.
I'm not really sure if you need to remove some dependencies of any of your direct dependencies or just want to clean jars downloaded.
If your problem is the first one, you can use "exclude" for that dependencies -> http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
If it's the second one, just remove your .m2/repository content and rebuild again your project
I am upgrading a project from Ant to Gradle. The project uses a aqapi13.jar(this is oracle aq jar. This is needed as the project reads from an oracle-queue and writes to an activemq queue.)
The ant project contains the jar aqapi13.jar in the libs folder. But iam trying to get this dependency from a repository instead of having it in the libs folder.
However, iam not able to find a repository which contains this jar. All the repositories that I have seen contain aqapi13-9i.jar, but not aqapi13.jar.
Anyone knows the difference between aqapi13.jar and aqapi13-9i.jar and how to get the needed aqapi13.jar from a repository.
Advance Thanks
Some dependencies are never found in public repositories because of the license they have.
One way to use this dependencies is to create your own repository (e.g. artifactory, nexus, archiva). Then you are free to put in every artifact you want (as long as you do not publish the repository). This repository can also serve as a mirror for maven.
Another way could be to mark this dependency as system scope.