Friday, September 23, 2011

Using Maven Profiles for Managing Dependencies in SOA Application


Recently we have enhanced our Continuous Deployment process by creating a bootstrap application that initiates DBs with tables and initial data. We use JPA/Hibernate to auto-create the tables from model objects. Since our application is composed from numerous services, each service carries its own part of the model, and there is a shared model used by all services. The bootstrap module depends on all the services through Maven's pom.xml, and populates the DB with tables from all dependent services.

The problem is that different clients use different combinations of services. Obviously, we don’t want to deploy services not used by a particular client, nor do we want to create tables needed by those unused services.  After some research, we settled on Maven Profiles that allow activating and deactivating different dependencies within the POM based on active profile.

Consider the following example:
The app contains three services (I wish only 3:)): S1, S2, S3, and a shared model M. Client A needs M, S1, S2, while Client B needs M, S2, S3 components. Originally, we would make bootstrap program depend on all 4 components and create all 4 database objects. So, in order not to pollute Client A’s environment with S3's DB objects that are not used, we introduced two Maven Profiles.

Default dependency (profile): M, S2
Profile-Client-A: S1 dependency
Profile-Client-B: S3 dependency

<profiles>       
        <profile>
        <id>Profile-Client-A</id>
        <dependencies>
                <dependency>
                        <artifactId>S1</artifactId>
                  </dependency>
        </dependencies>
        </profile>
        <profile>
        <id>Profile-Client-B</id>
        <dependencies>
                <dependency>
                        <artifactId>S3</artifactId>
            </dependency>
        </dependencies>
        </profile>
<
profiles>          
<dependencies>
      <dependency>
            <artifactId>S2</artifactId>
      </dependency>
      <dependency>
            <artifactId>M</artifactId>
      </dependency>
</
dependencies>


Each client has its own eclipse workspace that contains only components relevant to that client. In each workspace, the same bootstrap project is configured with a corresponding profile as active. The same is done in corresponding Hudson build jobs: build for Client A uses maven –P Profile-Client-A setting which “pulls in” only relevant dependencies.

By leveraging Maven Profiles we’re now able to remove all irrelevant dependencies from each of our clients. The workspaces look much cleaner, especially since in reality we have much more than just 3 services…

3 comments:

  1. Embroidery digitizing services provide the facility for the conversion of art work into a stitch file which can only be read by embroidery machine service.
    Embroidery Digitizing


    ReplyDelete