Usman Javaid
Usman Javaid

Reputation: 37

Automatically build Maven Project in case of a dependency upgrade

I am using Jenkins for CI/CD. Jenkins is integrated with my GIT account and as soon as there is an update in the code, Jenkins will build it automatically.

Lets suppose I am using Spring Framework and the version of the Spring framework gets updated. How can I use Jenkins and Maven to automatically build all the projects that were using the Spring framework?? Is there any plugin that will do it? Would be great if someone can share some tutorials/urls etc for the same?

Upvotes: 0

Views: 151

Answers (1)

Essex Boy
Essex Boy

Reputation: 7940

Create your own parent pom and use a dependency management section

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.greg</groupId>
  <artifactId>ear-example</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

    <dependencyManagement>
      <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
     </dependencies>
  </dependencyManagement>
</project>

Then in your child pom you will use the dependency but not specify a version, i.e. the version will be specified in the parent once for all children. You still need to include the dependency in each module.

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.greg</groupId>
    <artifactId>ear-example</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>example-ear</artifactId>
  <packaging>ear</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
    </dependencies>

Upvotes: 1

Related Questions