Search code examples
mavengradleliferayosgiliferay-dxp

Manually creating a deployable JAR for Liferay


I created a liferay workspace in gradle format and it basically only contains a theme and a TemplateContextContributor-module.

Now I want to build a maven "wrapper" around both artifacts to make them compatible with some other maven-processes/-plugins while keeping the original gradle structure. I dont want to use the liferay-maven-plugin or maven-tools to build those artifacts, because it seems to behave differently from the gradle/gulp toolset when it comes to compiling scss for example.

So I created some POMs from scratch for

  1. Theme
  2. TemplateContextContributor-Module

First off I will take about the mechanism for the theme, which is already working:

That wrapper uses the maven-war-plugin to bundle the contents of the build/-folder, where the previously built gradle artifact resides, into a WAR-file that can be deployed by Liferay without problems.

theme pom.xml:

<properties>
    <src.dir>src</src.dir>
    <com.liferay.portal.tools.theme.builder.outputDir>build</com.liferay.portal.tools.theme.builder.outputDir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

[...]

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <webResources>
            <resource>
                <directory>${com.liferay.portal.tools.theme.builder.outputDir}</directory>
                <excludes>
                    <exclude>**/*.sass-cache/</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>

However, I am having difficulties creating a OSGI-Compatible JAR-File for the module contents. It seems that only the META-INF/MANIFEST.MF does not contain the right information and I seemingly cannot generate it in a way that Liferay (or OSGI) understands.

this is the module pom.xml dependencies and plugins that I tried:

<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.scr.ds-annotations</artifactId>
    <version>1.2.10</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.liferay</groupId>
    <artifactId>com.liferay.gradle.plugins</artifactId>
    <version>3.9.9</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.liferay.portal</groupId>
    <artifactId>com.liferay.portal.kernel</artifactId>
    <version>2.0.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.service.component.annotations</artifactId>
    <version>1.3.0</version>
    <scope>provided</scope>
</dependency>

[...]

<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <version>3.3.0</version>
    <executions>
        <execution>
            <goals>
                <goal>bnd-process</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bndlib</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.liferay</groupId>
            <artifactId>com.liferay.ant.bnd</artifactId>
            <version>2.0.48</version>
        </dependency>
    </dependencies>
</plugin>
<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-scr-plugin</artifactId>
    <version>1.25.0</version>
    <executions>
        <execution>
            <id>generate-scr-scrdescriptor</id>
            <goals>
                <goal>scr</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I was able to create a JAR using the above but its' META-INF/MANIFEST.MF is not identical to the one produced by the gradle build:

differences, left is the liferay manifest.mf

I guess that's why Liferay does not deploy it. The log says "processing module xxx ....", but that never ends and the module does not work in Liferay.

These are the plugins I have tried in different combinations so far:

  • maven-build-plugin
  • maven-scr-plugin
  • maven-jar-plugin
  • maven-war-plugin
  • maven-compiler-plugin

Any help in creating a liferay-deployable module JAR would be great.


Solution

  • I'm not sure why you're manually building a maven wrapper for the Template Context Contributor. The Liferay (blade) samples are available for Liferay-workspace, pure Gradle as well as for Maven. I'd just go with the standard and not worry about re-inventing the wheel.

    To make this answer self-contained: The current pom.xml listed in the Template Context Contributor plugin is:

    <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>
        <artifactId>template-context-contributor</artifactId>
        <version>1.0.0</version>
        <packaging>jar</packaging>
    
        <parent>
            <groupId>blade</groupId>
            <artifactId>parent.bnd.bundle.plugin</artifactId>
            <version>1.0.0</version>
            <relativePath>../../parent.bnd.bundle.plugin</relativePath>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>com.liferay.portal</groupId>
                <artifactId>com.liferay.portal.kernel</artifactId>
                <version>2.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.portlet</groupId>
                <artifactId>portlet-api</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.service.component.annotations</artifactId>
                <version>1.3.0</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    
        <build>
            <finalName>com.liferay.blade.template.context.contributor-${project.version}</finalName>
        </build>
    </project>