pom.xml
The following is an example of a standard core pom<?xml version="1.0" encoding="UTF-8"?>
<project
I won't go into to much detail on the pom as it is pretty standard. You will see I am using jacoco to measure code coverage using sonarqube otherwise the plugins of interest are
<plugin>
Code
The following is an example of a standard core pom<?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>
<parent>
<artifactId>core</artifactId>
<packaging>bundle</packaging>
<name>Sample - Core</name>
<description>Core bundle for Sample</description>
<build>
<dependencies>
</project>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>
<parent>
<groupId>com.sample</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>base</artifactId>
<relativePath>../pom.xml</relativePath>
<artifactId>base</artifactId>
</parent><version>1.0.0-SNAPSHOT</version>
<artifactId>base</artifactId>
<relativePath>../pom.xml</relativePath>
<artifactId>base</artifactId>
<artifactId>core</artifactId>
<packaging>bundle</packaging>
<name>Sample - Core</name>
<description>Core bundle for Sample</description>
<build>
<plugins>
</build>
<plugin>
<plugin>
<plugin>
<plugin>
</plugins>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin><artifactId>maven-scr-plugin</artifactId>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
</plugin><artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<archive>
</configuration>
<Build-Time>${timestamp}</Build-Time>
<Build-Number>${buildNumber}</Build-Number>
<Build-Branch>${scmBranch}</Build-Branch>
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Export-Package> com.sample.core.*</Export-Package>
<Embed-Dependency>*;scope=compile|runtime;optional=false</Embed-Dependency>
<Sling-Model-Packages> com.sample.core</Sling-Model-Packages>
</instructions><Build-Number>${buildNumber}</Build-Number>
<Build-Branch>${scmBranch}</Build-Branch>
<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
<Export-Package> com.sample.core.*</Export-Package>
<Embed-Dependency>*;scope=compile|runtime;optional=false</Embed-Dependency>
<Sling-Model-Packages> com.sample.core</Sling-Model-Packages>
<archive>
<manifest>
</archive>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest><addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
</plugin><artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<execution>
</executions>
<id>pre-unit-test</id>
<goals>
<configuration>
</execution><goals>
<goal>prepare-agent</goal>
</goals><configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration><propertyName>surefireArgLine</propertyName>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<configuration&g
t; <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacocout</outputDirectory>
</configuration>
</execution><phase>test</phase>
<goals>
<goal>report</goal>
</goals><configuration&g
t; <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacocout</outputDirectory>
</configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
</plugin><artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
<argLine>${surefireArgLine}</argLine>
<includes>
<!-- Show 100% of the lines from the stack trace (doesn't work) -->
<trimStackTrace>false</trimStackTrace>
</configuration><argLine>${surefireArgLine}</argLine>
<includes>
<!-- Include unit tests within integration-test phase. -->
<include>**/JUnitTest*.java</include>
</includes><include>**/JUnitTest*.java</include>
<!-- Show 100% of the lines from the stack trace (doesn't work) -->
<trimStackTrace>false</trimStackTrace>
<dependencies>
<!-- AEM Dependencies --> <dependency>
<dependency>
<dependency>
<dependency>
<dependency>
<dependency>
<!-- Web Dependencies -->
<dependency>
<!-- Logging Dependencies -->
<dependency>
<dependency>
<!-- Commons Dependencies -->
<dependency>
<dependency>
<dependency>
<dependency>
<dependency>
<dependency>
<!-- Test Dependencies -->
<dependency>
<dependency>
</dependencies>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
</dependency><artifactId>org.apache.felix.scr</artifactId>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency><artifactId>org.apache.felix.scr.annotations</artifactId>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency><artifactId>jcr</artifactId>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<classifier>apis</classifier>
</dependency><artifactId>uber-jar</artifactId>
<classifier>apis</classifier>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.api</artifactId>
</dependency> <dependency><artifactId>org.apache.sling.models.api</artifactId>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.models.impl</artifactId>
</dependency><artifactId>org.apache.sling.models.impl</artifactId>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
</dependency><artifactId>geronimo-atinject_1.0_spec</artifactId>
<!-- Web Dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency><artifactId>servlet-api</artifactId>
<!-- Logging Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency><artifactId>slf4j-api</artifactId>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency><artifactId>slf4j-log4j12</artifactId>
<!-- Commons Dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>provided</scope>
</dependency><artifactId>commons-lang3</artifactId>
<scope>provided</scope>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency><artifactId>commons-collections</artifactId>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<scope>provided</scope>
</dependency><artifactId>commons-codec</artifactId>
<scope>provided</scope>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>provided</scope>
</dependency><artifactId>commons-io</artifactId>
<scope>provided</scope>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>compile</scope>
</dependency><artifactId>gson</artifactId>
<scope>compile</scope>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
</dependency><artifactId>commons-email</artifactId>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency><artifactId>junit</artifactId>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency><artifactId>mockito-all</artifactId>
I won't go into to much detail on the pom as it is pretty standard. You will see I am using jacoco to measure code coverage using sonarqube otherwise the plugins of interest are
<plugin>
<groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration>
</plugin>
<instructions>
</configuration>
<Import-Package>javax.inject;version=0.0.0,*</Import-Package> <Export-Package> com.sample.core.*</Export-Package> <Embed-Dependency>*;scope=compile|runtime;optional=false</Embed-Dependency> <Sling-Model-Packages> com.sample.core</Sling-Model-Packages>
</instructions> <archive>
<manifest>
</archive>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
In the maven-bundle-plugin plugin, I define a few extra features in its configuration
- instructions
- Import-Package
- Here we are telling the plugin to add javax.inject of any version as a dependency and all other declared packages
- Export-Package
- Here we are telling the plugin to add all of our packages to the manifest
- Embed-Dependency
- Here we are telling the plugin to embed all dependencies of type compile or runtime inside the built jar file
- Sling-Model-Packages
- Here we are telling the plugin to declare that any java file under com.sample.core can be a sling model
- archive
- manifest
- addDefaultImplementationEntries
- Here we are telling the plugin to write the Implementation version number details into the manifest
- addDefaultSpecificationEntries
- Here we are telling the plugin to write the Specification version number details into the manifest
Code
One thing you will see in most of the code examples in the following pages, although there are annotations that will help you configure AEM to use your components, in java side of the code, once you have the right structure, you are pretty much open to write your any java code you want, one note is that not all libraries will work in AEM so you will have to play around with which will and won't, and it is a good idea to see if AEM is pre-bundled with a version of a library.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.