Reusing ABS Artifact

This page provides a step-by-step guide to illustrate how to reuse ABS artifacts the combination of the ABS expressiveness and dependency management

Application

In this guide we consider an application that provides the calculate(Int n) method, which takes an integer as input and returns another integer as outputs. This application has an interface Application and the ABS module CoreArtifact provides one default implementation ApplicationImpl.

module CoreArtifact;

export Application, Main;

def Int fib(Int n) =
  case n {
    0 => 0;
    1 => 1;
    n => fib (n-1) + fib (n-2);
  };
        
interface Application {
  Int calculate(Int n);
}

class Application implements Application {
  Int calculate(Int n) {
    return fib(n);
  }
}

This can be packaged and deployed as an ABS package artifact (APK) using the following pom.xml

<project>
  ...
  <groupId>abs-productline-example</groupId>
  <artifactId>core-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  ...
  <build>
        <sourceDirectory>src/main/abs</sourceDirectory>
        <plugins>
          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                  <classesDirectory>${project.build.sourceDirectory}</classesDirectory>
                  <archive>
                    <manifestEntries>
                          <ABS-Package-Version>1.0</ABS-Package-Version>
                    </manifestEntries>
                  </archive>
                </configuration>
          </plugin>
        </plugins>
  </build>
  ...
</project>

Maven uses groupId:artifactId:version for identifying a particular artifact in the repository. These three fields act much like an address and timestamp in one. This marks a specific place in a repository, acting like a coordinate system for Maven projects. See Maven - POM Reference for more information

The above deployed APK artifact has the identification abs-productline-example:core-artifact:1.0-SNAPSHOT. As described in Deploying ABS artifact, invoke with the following command to deploy this APK artifact to the repository

mvn deploy

Reusing artifact

We define a separate ABS Maven project that uses this Application defined in the previous section.

module Products;

import * from CoreArtifact;

{ 
  Application app = new Application();
  Int result = app.calculate(10);
  assert result > 1;
}

To use the APK artifact abs-productline-example:core-artifact:1.0-SNAPSHOT deployed at the artifact repository in another ABS Maven project, the following dependency.../dependency clause needs to be declared in the pom.xml of the ABS Maven project as follows.

<project>
  ...
  <groupId>abs-productline-example</groupId>
  <artifactId>application</artifactId>
  <version>1.0-SNAPSHOT</version>
  ...
  <dependencies>
    <dependency>
      <groupId>abs-productline-example</groupId>
      <artifactId>core-artifact</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>eu.hats-project</groupId>
        <artifactId>abs-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <goals>
              <goal>genjava</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Here this maven project (abs-productline-example:application:1.0-SNAPSHOT) depends on artifact abs-productline-example:core-artifact:1.0-SNAPSHOT.

This build section of pom.xml specifies that during compile phase, the goal genjava of the abs-maven-plugin is invoked. The abs-maven-plugin gathers the dependencies specified in the pom.xml and resolves their physical location in the repository. As described in Generating Java, the Java backend is then invoked with the following command

mvn compile