Maven WAR Plugin / Jenkins repository connector: Omitting transitive dependencies? - maven

Situation
I have a multi-module Maven project. In it, I have several JAR artefacts, it then gets assembled as a WAR file. Thus, the WAR artefact depends on all kinds of JAR artefacts (it also has a WAR overlay), most of them with scope "compile".
Build and deployment to a repository are fine. But when I try to retrieve the WAR artefact, I have issues. previously, I used a simple wget to retrieve it from the Nexus API, but I wanted to try the Jenkins Repository Connector - not the least reason being that it actually shows a list of available versions.
I configure a repository in
Manage Jenkins -> Configure System -> Artifact Resolver
with the URL for our repo:
http://$NEXUS/nexus/content/repositories/releases/
then in the job, i add a parameter:
Maven Repository Artifact
and use the repository configured above, then i add
Artifact Resolver
as a build step and set it up.
Problem
I am not even sure on which side this should be solved: When I run the job to try to get the WAR file from the nexus, it also starts trying to retrieve all kinds of transitive dependencies (some of which are unaccessible to this user) and fails. What I need is just the WAR file. No transitive dependencies (since they're already packaged in the WAR).
The Repository Connector plugin doesn't seem to have a switch for this, and the Maven side it's probably perfectly OK to include those dependencies in the output POM.
Question
What can I do to either stop the repository connector from retrieving transitive dependencies or retrieve the WAR artefact in a different way? Also interesting for me (but a bit broad as a question) would be general ideas about doing this kind of workflow. E.g., does anyone use other ways of deploying the WAR into their Nexus?

i submitted a patch to the repository connector plugin.
my fork:
https://github.com/rmalchow/repository-connector-plugin
working on getting it to be merged:
https://github.com/jenkinsci/repository-connector-plugin/pull/10

Related

How to convert a Gradle project's dependencies into a local maven repository?

I am building a Java SDK that can be used to work on my app.
When I run ./gradlew :my-sdk-library:dependencies I get my transitive tree of deps.
All my customers refuse to access libraries on the internet. And they do not have a local maven proxy either, so I need to supply my sdk jars and the other open source jars too.
So I would like to convert that into a local maven repository so that I can send it to those who cannot access our maven repository that is hosted on Artifactory, nor Maven central.
The naive approach is the make a shaded (shadow) jar containing all the libraries then import it as a implementation file(path-to-shaded.jar). But that is not good because IDEs do not like huge 200MB shaded jar files. And you lose all the dependency management provided by the GAV values.
So I want to produce a local maven repository I can send along with the SDK.
So if this were Maven I would go to a fresh VM, run mvn install, then just copy the ~/.m2/repository folder and there you go.
I did find a project https://github.com/sinsongdev/gradle-cash-to-maven-repo which might work to create a local maven repo using the gradle cache, but it is not widely used. I'll give it a try.
Basically I want exactly what https://github.com/johnrengelman/shadow does but instead of producing an uber jar, to create a local maven repo.
Is there some option like that in Gradle to create an offline copy of the repo or cache so that developers who are behind strict firewalls can use your SDK?

Automated deployment of EAR project without obtain dependencies from a repository

Is it possible deploy an artifact (.ear) into a application server (AS) without obtain its dependencies from a repository?
Let's me explain: the maven project I'm trying to configure for deploy into a AS has 3 modules:
Web (.war - front end)
EJB (.ejb - back end)
Entity (.jar - entities classes)
These modules are wrapped into a EAR module and none of then are available in some repository (like Nexus or JFrog Artifactory). When I try to use Cargo Maven plugin or JBoss Deployment Maven Plugin, both notify that cannot resolve dependencies for these modules.
UPDATED (03/01/2019)
The issue is similar to that quoted in items 6 and 7 of the following link: http://webdev.jhuep.com/~jcs/ejava-javaee/coursedocs/content/html/ejb-basicex-eardeploy.html#ejb-basicex-eardeploy-testmodule
It's a workaround but worked. Instead of the project depends on an internal repository (like Nexus or JFrog Artifactory), it's possible defines a folder as a repository on the local machine using the Maven's parameter -Dmaven.repo.local. Thus, the plugin to deploy the artifact also can use this property and obtaining the others artifacts.
That is, to build the application on the current folder:
mvn -Dmaven.repo.local=. package
To deploy the application (.ear, in this case) using Cargo Maven Plugin, for example, without depending on an internal repository:
mvn -pl app-ear/ -Dmaven.repo.local=. cargo:redeploy
OBS: Using the maven.repo.local property, the folder defined as value will be fill with all dependencies of the project. In my case, it isn't a problem because this commands are been used on a continuous integration pipeline and all files and folder are discard on the final.

Maven artifacts for multiple environments

I am working on a project that uses Maven for build and Artifactory as Maven repository where the build is published. All works fine when there is just one set of configuration - build is created and published to Artifactory.
I need to be able to create a single WAR that contains necessary binaries and one additional artifact for each environment that contains environment specific resources (MongoDB connection URL and log4j2 xml). Deployment job in Jenkins should deploy WAR and environment specific resource JAR to the server.
I am stuck in creating and publishing artifacts. Approaches I tried and rejects are:
Maven profiles - rejected as it creates a separate WAR file for each environment. I find it illogical to create WAR files of few tens of MBs just to change few configurations.
Spring profiles - rejected as it uses code to solve deployment problem by deploying all configurations on all servers and relying on setting profile in environment + code change to read based on configured profile name.
Maven resources plugin - can be used to copy environment specific resources in appropriate directory structure; but does not get published to Artifactory during "deploy" phase.
Maven Jar plugin - can create attached JAR artifact, but attached artifacts cannot contain resource (or at least I could not figure out a way to include resources in attached JAR)
Maven build helper plugin - can publish individual files as attached artifacts, but file names are changed when deploying to Artifactory.
Multimodule POM - this approach could work to create resource artifact for each environment but has 2 disadvantages:
Updating version of main artifact needs update to all POMs (easy to miss out)
Not scalable - need to create separate POM if new environment is added.
It seems that Maven + Artifactory is not geared towards multi-environment scenario as there simply does not seem to be any straightforward solution. Am I missing something? What approach should I take?
Update
I solved the problem by using https://github.com/khmarbaise/multienv-maven-plugin. This lets me create one WAR and multiple JAR files:
- myapp.0.1.0.war
- myapp.0.1.0-dev.jar
- myapp.0.1.0-qa.jar
- myapp.0.1.0-prod.jar
I am stuck at next step. Install phase installs the JARs as WARs and subsequently Deploy phase uploads them to Artifactory as WARs. Any way to keep packaging type as JAR for the JARs?

Fetch all dependencies, put them in a new local Maven repository using Gradle

I have a Gradle project with several subprojects and many, many dependencies. I would like to have a simple way to tell Gradle to download all dependencies (including those under buildscript!) and put them in a local Maven/Ivy repository for later use. The Gradle script should then be able to pull all dependencies from the local repository.
Background: I need to build the application on a server which has absolutely no access to any public Maven repositories, so all dependencies must already be present on the host. I've tried a flat directory, but I have not found it easy to resolve the transitive dependencies, and managing them by hand is not an option. Copying the Gradle cache did not work, either.
Can anyone suggest something? Thanks.
I found a solution, namely to install Apache Archive (http://archiva.apache.org/) locally and set it up as a proxy. Then I copied the entire installation to the target-server and disabled the remote repositories. The dependencies could then be fetched locally.

How to use gradle without maven

Is it possible to use gradle without maven?
I ask this question because I've encounered a case where it isn't possible. For example, I have a project(let it be project A) which results in a jar file after the build. This project is used by another project(project B). When I change smth in project A, project B has to see those changes. In maven we could simply make mvn install on project A, then refresh dependencies on project B and changes hapen to be seen there(in project B)
Gradle has an opportunity to use maven plugin which can do the descibed thing. But in that case we rely on maven(maven repo in particular). I was founding information(seems on stackoverflow also) that gradle filestore, which is located in GRADLE_USER_HOME, is only a cache and can't be used for such purpose.
So, how to achieve that functionality in gradle
Thanks
Gradle downloads dependencies from repositories. These repositories can be Maven repositories, Ivy repositories, local Maven repositories or file repositories. So, to solve your use-case, you would indeed have to publish A to a repository, and to use this repository as the source of the A dependency in B.
See the documentation for more details.

Resources