Issues creating packages for offline repository

Someone who knows Maven well would have probably looked at the repository and noticed that there is no .jar file, but there is a .xar one.

In https://extensions.xwiki.org the type of each extension is indicated, but you still have to know about Maven dependencies types and make the link.

Alright thanks! I’ll just add it as footnote to the instructions then :slight_smile:

For anyone else who might stumble onto this topic with similar issues of not understanding the process, here is how its done (more or less). Thanks to @tmortagne for his help and patience.

To create your own XIP packages you need to complete the following steps(Linux):

Install Apache Maven(note: on most systems you should be able to download this via your package manager:
(Steps originally described in these guides https://tecadmin.net/install-apache-maven-on-centos/ https://dev.xwiki.org/xwiki/bin/view/Community/Building/#HInstallingMaven)

Download the latest release (Binary file, .tar.gz) from https://maven.apache.org/download.cgi , version 3.5.4 or greater

> cd /opt
> wget https://www-us.apache.org/dist/maven/maven-3/X.X.X/binaries/apache-maven-X.X.X-bin.tar.gz (replace URL with correct version)

Extract your archive

> sudo tar xzf apache-maven-X.X.X-bin.tar.gz
> sudo ln -s apache-maven-X.X.X maven

Configure environmental variables

> sudo nano /etc/profile.d/maven.sh

Add the following content to the file and save it:
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
export MAVEN_OPTS="-Xmx1024m"

Now load the variables

> source /etc/profile.d/maven.sh

Test if maven is correctly installed

> mvn -version

(If installed via package manager continue here)

Create a ~/.m2/settings.xml file with the XWiki custom remote repository defined as shown below

> nano ~/.m2/settings.xml

<settings>
  <profiles>
    <profile>
      <id>xwiki</id>
      <repositories>
        <repository>
          <id>xwiki-snapshots</id>
          <name>XWiki Nexus Snapshot Repository Proxy</name>
          <url>https://nexus.xwiki.org/nexus/content/groups/public-snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>xwiki-releases</id>
          <name>XWiki Nexus Releases Repository Proxy</name>
          <url>https://nexus.xwiki.org/nexus/content/groups/public</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>xwiki-snapshots</id>
          <name>XWiki Nexus Plugin Snapshot Repository Proxy</name>
          <url>https://nexus.xwiki.org/nexus/content/groups/public-snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
        <pluginRepository>
          <id>xwiki-releases</id>
          <name>XWiki Nexus Plugin Releases Repository Proxy</name>
          <url>https://nexus.xwiki.org/nexus/content/groups/public</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>xwiki</activeProfile>
  </activeProfiles>
</settings>

You have now installed and configured Apache Maven to be used for creating xwiki extension XIP files. The following information on how to generate the XIP file parcially comes from https://dev.xwiki.org/xwiki/bin/view/Community/ExtensionPlugin/#HExample and https://forum.xwiki.org/t/issues-creating-packages-for-offline-repository/10773

Create a new empty directory for the XIP file you would like to generate, in this example I'll use the ldap-authentication extension

> mkdir ldap-authentication

Inside the (empty) directory, create a pom.xml file and add the content below. Adjust configuration where needed for the extension you would like to package

> cd  ldap-authentication
> nano pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.xwiki.platform</groupId>
    <artifactId>xwiki-platform-distribution</artifactId>
    <!-- The version of XWiki where the extension is planned to be installed -->
    <version>14.1</version>
  </parent>
  <!-- The groupId is required to be set, but is not used so any value will do -->
  <groupId>org.xwiki.contrib.ldap</groupId>
  <!-- The artifactId is used to generate the file name of the package, the line below will output the file 'ldap-xip-14.1.xip' -->
  <artifactId>ldap-xip</artifactId>
  <packaging>xip</packaging>
  <properties>
    <!-- It's expected for some enforcer rules to fail with a dependency that was not designed to be built with this version of XWiki -->
    <xwiki.enforcer.skip>true</xwiki.enforcer.skip>
  </properties>
  <!-- Here you only need to define the extension you want to package. Maven will automatically include the required dependencies. To find the correct value look up the extension in the store, in this case https://extensions.xwiki.org/xwiki/bin/view/Extension/LDAP/Authenticator/ , scroll to the bottom where it says 'Dependencies for this extension', the value between the brackets is what you need. the first part until the : is the groupId value, the second part after the : is the artifactId, and the last part is the version number. Copy the bits of information and replace the values below -->
  <dependencies>
    <dependency>
      <groupId>org.xwiki.contrib.ldap</groupId>
      <artifactId>ldap-authenticator</artifactId>
      <version>9.7.4</version>
    </dependency>
  </dependencies>
  <-- Leave the settings below as they are -->
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.xwiki.commons</groupId>
          <artifactId>xwiki-commons-tool-extension-plugin</artifactId>
          <version>${commons.version}</version>
          <configuration>
            <coreExtensions>
              <!-- We exclude what is already in the WAR -->
              <coreExtension>
                <groupId>org.xwiki.platform</groupId>
                <artifactId>xwiki-platform-distribution-war-dependencies</artifactId>
                <version>${platform.version}</version>
                <type>pom</type>
              </coreExtension>
            </coreExtensions>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Save the file. You can now build your XIP package

> mvn package

When successful the package will be in the newly created 'target' subdirectory. If for some reason something was messed up and you have to retry but run into some warnings that previous settings are being tried, then include -U to your command. (mvn package -U)

If you run into a 'could not resolve dependancy' chances are you need to specify the dependency type as 'xar' as shown below

    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-export-pdf-ui</artifactId>
      <version>14.6</version>
      <type>xar</type>
    </dependency>

Handy tool: https://snippets.xwiki.org/xwiki/bin/view/Extension/XIPImporter/

Hi,

One more question for an error I run in to. I am trying to package ‘Ratings Application’ and I run into the following error;

[ERROR] Failed to execute goal org.xwiki.commons:xwiki-commons-tool-extension-plugin:14.1:xip (default-xip) on project rating-41-xip: Failed to resolve dependencies for project [MavenProject: org.xwiki.platform:rating-41-xip:14.1 @ /home/eve/rating4.1/pom.xml] dependencies: There is already a core extension covering feature [org.xwiki.platform:xwiki-platform-ratings-api] -> [Help 1]

Do you know why this is happening? The extension doesn’t seem to be part of the standard offered offline XIP package.

This error suggests that you have xwiki-platform-ratings-api in your dependencies, but this one is part of the excluded ones (already part of XWiki Standard). Maybe you mixed with xwiki-platform-ratings-ui (which indeed is not part of XWiki Standard) ?

Oh bloody hell, you’re right, sorry. Kept reading over the incorrect copied name (-api instead of -ui). Thanks once again :x