Gradle dependency jars downloaded in a folder with different name - java

I am running a Spring Boot application through a gradle build and I observe that the dependency jars which are downloaded are kept in a subfolder inside the gradle caches folder, which has a different name.
For example, the gradle dependencies are downloaded in:
/root/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-gradle-plugin/2.0.5.RELEASE/2c7ddace2abd741a76720a29365d2dcd7633ef77/spring-boot-gradle-plugin-2.0.5.RELEASE.jar
However, I don't understand why the hash key (seems like one) is generated as a subfolder and the jar is inside the subfolder.
As a result of this, the dependency is not being found when I try to load it later during gradle build from a local repository. It shows an error message like could not resolve dependency.
Also why is the dependency being downloaded as org.springframework.boot and not org/springframework/boot? Since during picking up, it is expecting the dependency to be in a location like this.
Any help on how to resolve this will be appreciated. Thank you.

Related

Java azure-function deployment bitbucket pipeline, gives NoSuchMethodException. How to resolve dependencies of another dependent project?

I have two java projects. A java azure function, with another child maven project. This another project have other dependencies like, jackson-databind, apache etc. Using bitbucket pipeline, i am able to successfully deploy it on azure. But while running, it is not able to read dependencies of child dependent project. Though all my parent/child jars are fat jars, the lib folder under target, doesnt include dependencies of child dependent project. It has dependency of child project though. On local, the lib folder contains all dependencies, please suggest what should be on pipeline.
Tried with below configuration
bitbucket-pipeline
getting NoSuchMethodError, though the .class file is present.

Unable to create an object of the class from Maven type project

My pom.xml has only 1 dependency -
<dependency>
<groupId>com.shubham.TestNexus</groupId>
<artifactId>TestNexus</artifactId>
<version>1.0</version>
</dependency>
This is a test jar that I have created and uploaded to my local nexus repository. I could see that when I am building the project, maven is downloading the jar and placing it in the Maven Dependencies directory. I could see the same jar added to the classpath as well.
This jar has nothing but a simple helloWorld printing method.
Now when I am using this jar in my project, it is not allowing me to create the object of the class inside this jar.
And, when I tried making a non-maven java project and added the jar manually to the classpath I am able to create the object of the class. Can anyone please help here.
I found the solution to the problem, seems like it doesn't allow the jars that have classes, present in the default package. I created another jar and put it inside a package and it worked. Thanks a lot everyone.
I work with maven aswell. When i have problems with dependencies to try all this steps:
Use the maven clean and install commands.
Use the maven update project to force it.
Refresh all the project.
If it doesn't work the problem could be on m2 repo.

How do I get a local Maven package to bring in its dependencies?

I have written a series of classes that I want to turn into a company library. Managing all it's dependencies was a pain so I made a Maven project for it to be handled automatically.
I have packaged my library project into a .jar and added it to my local Maven repository. I can now list it in my application project's pom.xml, it get's brought in just like any other dependency and works great.
The problem is the dependencies of my library do not get brought in. It seems like this should be straight forward but trying to copy other packages in the Maven repository doesn't work.
Right now my jar consists of two directories:
com\company\package\Main.class
And:
META-INF\maven\com.company\package\pom.xml
Where do I need to put the pom.xml file for Maven to go get my dependency's dependencies? Is there something else in the .jar build that I am missing?
The Maven POM file (pom.xml), which describes the project/module, is usually placed in the root directory.
The POM file can then be picked up by your Maven installation, which will automatically configure the project, which means also downloading dependencies from their repositories.
For an example of an artifact deployed to a repository, see
http://central.maven.org/maven2/org/springframework/spring-core/5.1.5.RELEASE/

Maven Multi-Project is not Deployed Correctly to Maven Central

I have a project (cc.renken.pipeio) at maven central. Previously, it was a simple maven-project and upload worked fine. Later on I changed it into a multi-module project with the configuration found below.
main project pom
submodule pom
The build process is done by calling
mvn package deploy
However, now only the main project (pipeio) is uploaded (the .pom files), the javadoc and source code from the submodules are generated in the target folders within the submodules. But these are not uploaded. What am I missing in the configuration?
Found out, that it was a caching problem in the definition of the gitlab-build script. I accidently cached the .git/ repositories which led to overwriting the actual .git/ repositories. This led to side effects, where the submodules where not build because they just weren't there. After correcting the cache settings everything works fine now.
So this problem is not maven or maven multi-project related actually.

Idea IntelliJ. how creating maven project. what about pom.xml and .iml files

i just started with java, and created a project.
its maven project (i hadn't use maven yet)
so my project have two modules A and B.
and B depends on A, and A depends on some from remote maven repo. and B also depends on some remote repo.
its works fine in Idea IntelliJ and build jars fine.
but afaik .iml files are Idea IntelliJ specific. and pom.xml is maven specific.
and when i inspect files why all depedecy of project is written in .iml files and .idea dir instead of pom.xml(s)
if you want to see the real world source then here it is but its alpha project for learning java deeply.
and when i try to build project on travis-ci.org it unable to resolve dependencies of project
Meghraj,
I have forked your WebTrimmer repo here : https://github.com/ajorpheus/WebTrimmer and fixed a couple of issues which were preventing a successful build:
The travisci fails because you have three jars in the lib folder which are not available to the CI since it's doing a maven build. The fix was to remove those three jars and introduce corresponding maven dependencies as in this commit.
While adding the maven dependencies an exclusion was needed as noted here : The following artifacts could not be resolved: javax.jms:jms:jar:1.1
The WebTrimmerUI depends on the classes in it's sibling module WebTrimmerEngine, therefore a corresponding dependency is needed.
I have converted the project into a pure maven project which is IDE-agnostic. With the above changes, I can build the project from command line and expect that the travisci should be able to as well.
Regarding the question about why the dependencies are duplicated in .iml --- That's not the reason the CI job fails. The dependencies in that file are a snapshot of the dependencies in the pom.xml. This snapshot is updated when the maven project is re-imported manually by the user, or automatically if the maven project is set to 'Auto-Import'.
As Peter Lawrey mentioned in his comment above, if you add a jar to the project, maven does not know about it and it will be present only in the .iml file.
In general, to search and add a maven dependency, the following has always worked for me: https://stackoverflow.com/a/10178586/325742
Hope this helps !
You need to add dependencies to the pom yourself. The .iml files are for storing project specific settings for whatever project you are currently working on.
Having the pom files allows your maven builds to be IDE independent where as the .iml files require you to have IntelliJ.
You can exclude the .iml files from and version control you are using. You can also open an existing maven project directly via IntelliJ by opening its pom.xml and IntelliJ can auto import everything specified in the pom file and will generate new .iml files.

Categories