In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "dependency management among maven projects". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "dependency Management among multiple projects in maven".
1. Apply Aggregation to manage multiple sub-projects
There is an Aggregation (aggregation) in Maven, you can add multiple projects to a pom.xml as modules, and then tell Jenkins the top-level pom.xml, and you can automatically take the source code of these projects from Git, build all the subprojects and run the corresponding test programs. I am using TestNG here.
For example, I have two maven projects, client and email_sender, and I want to compile and test them once and add a pom.xml to the directory above the two project folders, as follows:
4.0.0 com.kaimei.datacenter cml 2.0 pom client email_sender
Then just tell the path to the pom.xml in Jenkins. Click build now to test, you can see that the two subprojects have been downloaded and compiled, running the TestNG test program.
Note that the module name should be the directory name of the subproject.
two。 Dependency management among multiple projects
There is no relationship between the client and email_sender projects in the above example. In order to demonstrate the build management of continuous integration in the dependency tree, we now set up a new maven project called mongo_utility, which provides a DBManager-like link that encapsulates MongoDB. The code comes from another article I wrote: http://blog.csdn.net/sheismylife/article/details/7090526.
Both the client project and the email_sender project connect to MongoDB through the DBManager class. So they all have this paragraph in their pom.xml:
Com.kaimei.datacenter mongo_utility 1.0
Build was successful. Looking closely at the behavior of Console Output,Jenkins is not quite the same as using mvn clean compile directly. Jenkins takes out the mongo_utility source code, recompiles it, installs it to the local repository, and then compiles the other two projects. If you type mvn clean compile directly, mongo_utility-1.0.jar will be downloaded and installed directly from the private server and will not be compiled.
3. Multiple projects share the same settings
Mongodb java library is used in both client,email_sender and mongo_utility projects, and it is not necessary to have the same dependency defined in their respective pom.xml for ease of management. Maven treats the pom.xml of each project as a project object, and inheritance allows them to share the same configuration.
Add mongodb dependencies to the top-level pom.xml:
Org.mongodb mongo-java-driver 2.7.2
Then delete the above dependencies in the pom.xml of the client,mongo_utility and email_sender projects, and add the following configuration:
Com.kaimei.datacenter cml 1.0.. / pom.xml
Then test it, and it's done.
4. The module is deployed on the nexus server
If you want to deploy a module project, such as the mongo_utility project here, to the nexus server, you need to adjust the pom.xml of the top-level directory, plus the following configuration:
Sheismylife http://S1:8081/nexus/content/repositories/sheismylife
But all three module projects automatically inherit deploy functionality. In fact, I just want to deploy the mongo-utility module to nexus, so let's put the problem here for the time being.
Then execute mvn clean deploy on the top-level directory, and everything goes well. Submit the code to the git repository, then modify the project configuration page of Jenkins to add the clean deploy command.
Click the Build Now button to see the results, everything OK. It is worth mentioning that if you execute correctly from the mvn command line and error from the Jenkins, restart the Jenkins service. I've come across it several times. It seems that Jenkins has bug.
5. Deploy a web project to Glassfish or Tomcat through Jenkins
The basic practice is to complete the deployment through the plugin of the Maven project. One problem is that if the web project and several other projects are aggregated as modules of a large project and inherit a parent pom.xml, how can you compile all the modules with one Maven command, deploy to the nexus private server, and publish the web project to Glassfish or Tomcat. It is still under study and hopes to be able to achieve this function through Maven.
6. Sequential execution between multiple project on a Jenkins
This is very simple, the project configuration of Jenkins can be set to build after a certain project, or build other project after this project build.
7. Remote calls between multiple Jenkins
Jenkins An on S1 calls a shell script, such as curl http://S2/job/test/build
The test project of Jenkins B on S2 will be triggered
At this point, I believe you have a deeper understanding of "dependency management between maven projects". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.