Gradle Local Dependency Testing - maven

I have 3 gradle projects, projectA, projectB, projectC. All of which build a jar file named projectX-0.0.0.jar. On my jenkins server, all of these projects deploy these jars to my companies artifactory.
In projectA, I have multiple compile dependencies used throughout my entire project. Then in project B, I include project A by stating: compile group: 'com.company.projectName', name: 'projectA, version '0.0.0' So I can use these dependencies (i.e. slf4j) I do the same for projectC to include projectB dependencies, which in result includes projectA's dependencies.
This works great for our jenkins servers on deployment, after I have pushed the code to the server, however when trying to test locally I can not get the dependencies to update for testing my code.
I have tried:
Updating the gradle cache that downloads project A from artifactory with locally built project A jar. Located in C:/users/username/.gradle/caches/path-to-jar.
Removed the compile group: 'com.company.projectName', name: 'projectA, version '0.0.0' and replaced it with compile files('libs/projectA-0.0.0.jar'), placing projectA's jar within a lib folder in projectB
Using gradle offline mode in IntelliJ and repeating #1
Going offline completely on my pc and repeating #1
With all 4 attempts above I still have not been able to resolve dependencies declared in project A for project B.
My goal is to be able to update a compile,testCompile,runtime,etc. dependency in my projectA.gradle file, and then run my projects down my pipeline to ensure this update effects the dependencies in my project as I intended.

You need to update the .jar and .pom file within your gradle cache. The .jar file contains the source code while the pom contains the dependencies you brought in the previous project. Using a gradlew clean build install you can create the jar and the pom.
So to solve your problem, do a gradle build clean install on project-a. Grab the jar and pom from the build file generated and replace the project-a.jar and project-a.pom within the cache. Then do the same for project-b and you will see the changes in project-c after a gradle refresh.

Related

How to reference local Gradle project from Maven build as dependency?

I have several Gradle library projects and main Ant spring web-app project (historically). I'd like to replace Ant with Maven for main project while keeping existing Gradle projects nature.
Is it possible to refer local Gradle projects from pom.xml as local dependencies of Maven project?
Search readily gives me the opposite - "how to refer maven projects from gradle builds", but not my case.
Gradle always builds locally build/libs (or distributions); the only easy way to share the build dependencies between completely different projects is 'as maven repository dependencies'
in your case the options are
Work Local Builds only
add the maven plugin to the gradle builds - do local install
and refer them in the maven build locally.
Build Anywhere
Your Gradle builds publish artefacts to your local nexus
and you refer them properly in your dependencies
--
Gradle by default does not have 'maven install'; it can be added using the maven plugin see - https://docs.gradle.org/current/userguide/maven_plugin.html#header.

IntelliJ uses snapshots with timestamps instead of -SNAPSHOT to build artifact

I have a project with snapshot dependencies. For simplification let's say that there is an project A which depends on library B-0.1-SNAPSHOT.
A depends on B
B resides within Nexus repository as a snapshot. I can see that it is stored with timestamp so the actual name in Nexus is something like: B-0.1-20141126.171716-67.jar
After executing:
mvn clean install -U
on project A, dependency B is downloaded from Nexus to my local repository. There I can find two jars of library B:
B-0.1-SNAPSHOT.jar
B-0.1-20141126.171716-67.jar
So far so good.
After maven build is complete I can see that B-0.1-SNAPSHOT.jar was taken to build A artifact (.war file)
I also have project A imported to IntelliJ as a maven project. There I run it on Tomcat. Project is build by IntelliJ and B-0.1-20141126.171716-67.jar is added to .war file.
At the end I have .war with both B-0.1-SNAPSHOT.jar and B-0.1-20141126.171716-67.jar within WEB-INF/lib directory.
For me is seems like a bug in IntelliJ because B-0.1-SNAPSHOT.jar should be taken from local maven repository... not the timespamped version. Is there any way to force IntelliJ to act propeply?
Maven version is 3.2.3, IntelliJ 14.0.1 (but the same behavior was on 13).
I was faced to the same problem today, and I found how to disable this feature.
F4 on your module, and go to artifacts then select the name of your artifact webapp:exploded and check the show contents radio at the bottom of the frame.
Go to WEB-INF/lib and search for your dependecy B-0.1-SNAPSHOT.jar and expand the line you will see a compile output folder in it, just remove it, then repackage and run, you will now only have the B-0.1-SNAPSHOT.jar and the one with the timestamp should be gone.
The downside of this is that you will have to make sure to mvn install your B module before running the A module within IntelliJ, because IntelliJ won't package your dependency and bundle it with the code you've just edited but not installed in your local maven repository.

where to place customer jar in maven project structure

I have a dependency application jar from other maven applications,and currently added it to my application path,
I want to know how this application related jar can be automatically moved my local repository folders.
I think it should be placed in somewhere in maven project folder structure so that when maven build the module it automatically moves to the repository.
Dependent project:
If built with maven, you would issue a mvn install, when building it.
If not built with maven, install it locally using mvn install:install-file
http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html

Where to download Netflix Astyanax dependencies?

I want to include Astyanax into my project. I checkout the code from github and compiled it with "gradlew build". I am not familiar with gradle.
I include the Astyanx jar files manually into my project. When I run it, it complains about missing Jar.
I wonder, where I can download all the dependencies bundle for Astyanax?
Java library projects often don't provide a single download location for their dependencies. Instead, you would typically use a build tool that supports Maven repositories (e.g. Maven or Gradle) for your own project, which would then automatically download required dependencies behind the scenes.
If you do want to get hold of all dependencies for the Astyanax project, try to add the following to its build.gradle:
task copyLibs(type: Copy) {
from configurations.runtime
into "libs"
}
Running gradlew copyLibs should then copy all (compile and runtime) dependencies into the libs directory.

tycho plugin + maven-dependency-plugin: copy dependencies from local projects instead repositories

Main Goal: deploy a project as jar and eclipse-plugin
current state: project builds fine as jar package
Now i want to create a second project which wraps the jar project as eclipse plugin
use tycho-maven-plugin to create eclipse-plugin
add the jar of the original project (with copy-dependency)
add an Activator
export packages from jar
create correct MANIFEST.MF
i tried to copy the jar with copy-dependencies bound to create-resources. This works as long the jar is found in repository, but the local project gets ignored.
This results in a build failure since the jar is not found.
Is it possible to tell copy-dependencies to take the jar from the target directory of the project? Or should i use some other method than using tycho?
Edit:
I solved my problem with 4 projects:
normal project (nothing special here)
the wrapper project using tycho maven and copy-dependencies.
bound copy dependencies to some goal before compile (e.g. generate-resources). Excluded all artefactid which were set as dependency in the MANIFEST.MF.
a prepare project, which calls the normal project and installs it into the repo. This is needed because the tycho-maven-plugin is bound to validate and it is not possible to call the exec plugin beforehand (at least not easy).
a multi module project which calls the prepare project before the wrapper project.
Build your local project (which artifact was missed) with "mvm install". It will be deployed in your local repository ($USER_HOME$/.m2/repositories). After this dependency should be resolved.
Alternatively you can "mvn deploy" if you have local company maven repository like Artifactory or Nexus.

Resources