Jenkins build with differents maven repository - java

I have an Jenkins build machine with the follow situation:
1. MY_MAVEN_PROJECT
2. MY_MAVEN_PROJECT_BRANCH_1.0
3. MY_MAVEN_PROJECT_ nightly_build
All of these task use a common maven repository located in ~/m2./repository
The problem is that the all builds use the same maven repository,
when I execute the nightly build I’d like to remove also the maven repository, in order to have a very clean situation.
So I was wondering if it is possible to have an situation like this:
1. MY_MAVEN_PROJECT
|_ workspace maven repository (workspace/MY_MAVEN_PROJECT/m2./repository)
2. MY_MAVEN_PROJECT_BRANCH_1.0
|_ workspace maven repository (workspace/ MY_MAVEN_PROJECT_BRANCH_1.0/ m2./repository)
3.MY_MAVEN_PROJECT_ nightly_build
|_ workspace maven repository(workspace/MY_MAVEN_PROJECT_ nightly_build/m2./repository)
Any help is appreciated

In Jenkins > maven build step > advanced settings, there is a checkbox that says "Use private Maven repository".
When this option is checked, Jenkins will tell Maven to use $WORKSPACE/.repository as the local Maven repository. This means each job will get its own isolated Maven repository just for itself.

Related

How can i do a gradle publish on teamcity to publish a gradle build that uses the maven plugin?

I have teamcity currently configured to use the maven mojo, to publish the gradle jar as a nexus snapshot with just the gav.
I observe that if i use the maven plugin and do a gradle install in the IDE, i am able to see the generated pom.
1) Can i use this pom to publish the jar in nexus repo in teamcity ? I know that i can do it for a pure maven build by using it's pom.
2) Is there a way to not use this pom, and istead configure teamcity build steps to publish from gradle build directly ?
Gradle can of course take care of the publication. It will leverage the build information to produce a POM file that represents best what is declared in your project.
It will then be trivial to invoke that Gradle task from the Teamcity build.
Have a look at the publishing documentation for details on how to set it up.

Jenkins: build failing because of third party jar : Could not find artifact com.oracle:ojdbc7:jar:12.1.0.1.0

On my windows machine: I have setup jenkins CI to automatically create build.
But every time build is failing because of the third party ojdbc7.jar file.
[ERROR] Failed to execute goal on project abc-cc-onboarding-repository: Could not resolve dependencies for project com.abc.cc:abc-cc-onboarding-repository:jar:1.0-SNAPSHOT: Could not find artifact com.oracle:ojdbc7:jar:12.1.0.1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
When I manually build using: mvn -U clean build, everything works fine.
because I have manually installed ojdbc7.jar in the local repository (.m2)
Something is wrong with the Jenkins integration with maven.
Can anybody suggest on this?
Something is wrong with the Jenkins integration with maven.
No. That's not the problem. Jenkins integration with Maven works just fine.
The problem is that ojdbc7.jar is not in the Maven Central repo ... which is the default place that Maven looks. (Or at least, it is not in Maven Central not with those artifact "coordinates". There are some ojdbc artifacts with different coordinates. YMMV.)
The real problem is that Oracle don't want you to download Oracle JARs from Maven Central. Oracle want you to download from their Maven repo instead.
One solution is to do what you have been doing. Simply add the artifact to your local repo (or Jenkins' local repo for the project). But you are not happy with that.
The other solution is to configure the remote repos that Maven uses.
Here is a page that explains how to configure (stand alone) Maven to include the Oracle repo:
Get Oracle JDBC drivers from the Oracle Maven Repository - NetBeans, Eclipse & Intellij
For the Jenkins case, you need to configure the settings that the Jenkins server uses:
How to manage maven settings.xml on a shared jenkins server?
This lists various ways of doing this.
SOLUTION THAT WORKED FOR ME:
What i found after the analysis and it resolved my problem, hope it will help somebody like me.
Actually jenkins creates a separate repository for separate projects.
like if i have 10 project in my jenkins workspace then it creates 10 repository one for each project (inside the project on top level we can see that).
so now i installed manually ojdbc7.jar inside my jenkins project repo and it solved my problem.
The above error occurs mostly when Jenkins is unable to download the oracle jar.
To sort the above issue
Create the settings.xml and settings-security.xml files in Jenkins through the "Managed files" in the administration home. To do that follow this link - https://wiki.jenkins.io/display/JENKINS/Config+File+Provider+Plugin#ConfigFileProviderPlugin-Howitworks
NB: Ensure to put in your Oracle credentials in these two files. To do that follow this link - https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9017
In your jenkins project under configurations in Build Environments include this files under the option Provide Configuration files. As shown below:
Once done build it and it should work.

Unable to build Shopizer project

When I execute the mvn install inside the project sm-core of Shopizer, I am getting the below error:
[ERROR] Failed to execute goal on project sm-core:
Could not resolve dependencies for project
com.shopizer:sm-core:jar:2.0.3-SNAPSHOT: The following
artifacts could not be resolved: com.shopizer:sm-core-model:
jar:2.0.3-SNAPSHOT, com.shopizer:sm-core-modules:jar:2.0.3-SNAPSHOT:
Failure to find com.shopizer:sm-core-model:jar:2.0.3-SNAPSHOT
in http://maven.springframework.org/snapshot was
cached in the local repository, resolution will not be
reattempted until the update interval of
org.springframework.maven.snapshot has elapsed or updates
are forced -> [Help 1]
How can I solve it?
The Shopizer project is actually a multi-module Maven project. This means that it has a root pom.xml of packaging pom and declares several <modules>.
Those modules, which are Maven project themselves, are typically found as sub-folders under this root folder, which is the case here: there are 4 sub-folders, which are exactly the 4 Maven modules. To compile those sort of projects, you need to invoke Maven from the root project, in this case, shopizer.
You may ask why. In a multi-module Maven project, there is generally inter-dependencies: one module is dependent on another. In this case, the scm-core module that you're trying to build has dependencies on both sm-core-model and sm-core-modules, which are two modules of that project. So when you're building it, Maven will try to look in your local repository those artifacts. The problem is that it won't find them: they have never been built before. Maven won't also find them on a public repository because we're dealing with SNAPSHOT dependencies. The solution is to start the build on the top project: Maven will order correctly the reactor so that when it builds scm-core, both those dependencies will have been built.
Put simply: in a multi-module Maven project, you should practically always invoke Maven commands from the root POM.
To solve your problem, you can check-out the 2.0.3 branch (which is the latest branch) and invoke mvn clean install on the root POM. I did just that successfully.

Jenkins - Ant Build Maven Deploy

I have a project with a complicated ant build that we would like to remain as ant at the moment (will be converted to maven eventually).
I am using jenkins at the moment to build/test our application. After build/test, I now want to push the built artefact to a Nexus repository.
For a Maven project, I can use the post build action "Deploy Artefacts to Maven Repository" to do this.
Whats the best way to structure my Jenkins jobs to achieve an ant build and then deploy the code to Nexus?
Have you seen the example Ant scripts in the Sonatype website?
They actually include pushing artefacts to Nexus:
http://central.sonatype.org/pages/apache-ant.html#signing-and-deployments-using-the-maven-ant-tasks
Or there is also some more docs at Sonatype:
http://books.sonatype.com/nexus-book/reference/staging-deployment.html#staging-ant

maven - using local source instead of external dependency

If someone could help me out here it would save me a lot of time.
I maintain an open source library that gets pushed out to a sonatype repository. I make changes to that library a few times a day and push it out to the 1.0_snapshot build using mvn deploy.
Let's call it project1
I work constantly in another project that uses that library let's call it project2.
Right now, whenever i make changes to project 1 or 2, i need to first build and deploy project 1 to the repo, then build project 2 so it downloads a fresh copy of project1.jar
Project2 has Project1 as a dependency in a pom.xml:
<dependency>
<groupId>com.group</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
in order to build in a way where all of my changes can be tested, I have to do something like this:
mvn -f ./project1/pom.xml clean deploy
mvn -U -f ./project2/pom.xml clean package
this uploads my project1.jar to sonatype, then project2 downloads the new snapshot and builds it.
This is a simplified picture of what i'm doing on a larger scale, where my compiles take 5 minutes of up and downloads.
Question: What is the proper way to use maven so it knows to use the source of project1 in a dependency in project 2?
IDE:
install m2e in eclipse
import your both projects into workspace
from consumer project (right click > maven > enable workspace resolution)
this will put project2's classes in classpath from its target/classes instead of the actual jar
native straight maven:
You can create a maven project tree, if this two are open source project going through same build cycle it must have one already, if they are not related but related for your usecase then you can temporarily create a maven tree on top of these 2 projects and build the top parent it will build from bottom up in one command
it will find the leaf project, build it install it in maven's cache and now while building projectA it will refer it from maven's cache so no need to deploy to sonatype
You can also point project2 to build using offline mode :
mvn -o package
Then you drop the upload part of the project1 build to the remote repo.
Check the following link: Intro to repositories and How do I configure Maven for offline development?

Categories