The need is to consume content of a dedicated type provided as binary content in a maven repository. An example for this might be to consume java script files, technically provided as a zip archive. In such as a scenario, consuming a dedicated archive might require to also consume archives or content required by the directly consumed component. For example, java script files might use other java script classes, contained in a dependent component. Here it is extremely useful to get all the dependent content just by establishing a dependency to the initially desired component. The know-how about the further dependent stuff is typically only available at the directly consumed component. It should be urgently avoided to force consumers to know about internal dependencies.
In Maven dependencies are declared with a specific type. This type is mapped to a technical artifact suffix. By default, type and suffix are identical - for example, a zip dependency is mapped to a .zip artifact. The definition of such a type additionally allows to declare the usage of a transitive dependency resolution. For example, there is a type "js" that is mapped to the suffix .zip and declares such a transitive resolution. As a result referring to an "js" artifact means to resolve the .zip file of the directly addressed maven coordinates including all js dependencies, declared by this component.
Such a type definition is defined in a components.xml that typically comes with a maven plugin.
How artifacts should be handled is described by an artifact handler defined inside the components.xml of a maven plugin.
There are two properites that are important for our use case.
The components.xml file looks typically like this:
<component-set> <components> <component> <role>org.apache.maven.artifact.handler.ArtifactHandler</role> <role-hint>js</role-hint> <!-- The type of the dependency as used inside the dependency section --> <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation> <configuration> <extension>zip</extension> <!-- The file extension of the main artifact. --> <language>java-script</language> <addedToClasspath>false</addedToClasspath> <includesDependencies>false</includesDependencies> <!-- Describes whether or not this artifact contains it dependencies. --> </configuration> </component> </components> </component-set>
<build> [...] <plugins> [...] <plugin> <groupId>THE_GROUP_ID</groupId> <artifactId>THE_ARTIFACT_ID</artifactId> <version>THE_VERSION</version> <extensions>true</extensions> <!-- Important. If not present the artifact handler defined in the components.xml is not taken into account --> </plugin> [...] </plugins> </build> [...]
<build> <plugins> <plugin> <groupId>com.sap.prd.mobile.ios.mios</groupId> <artifactId>xcode-maven-plugin</artifactId> <version>1.14.5</version> <configuration> <additionalPackagingTypes> <js>USAGE_TYPE</js> </additionalPackagingTypes> </configuration> <extensions>true</extensions> </plugin> ..... </plugins> </build>
USAGE_TYPE could be as follows:
Example:
<dependencies> <dependency> <groupId>GROUP_ID</groupId> <artifactId>ARTIFACT_ID</artifactId> <version>VERSION</version> <type>js</type> <!-- The type is defined here --> </dependency> </dependencies>
Open a Terminal and go to the folder containing the pom.xml of your project. Run the following command: mvn initialize
For