I take that back, I didn’t notice the 'sourceDirectory’ property in the
Assembly mojo, which does exactly what I need.
I tested a locally modified plugin, with only this change:
if (targetFile != null) {// &&
project.getPackaging().equals("karaf-assembly")) {
serverName = targetFile.getName();
} else {
serverName = artifact.getArtifactId() + "-" +
artifact.getVersion();
}
Changed the pom packaging:
<packaging>pom</packaging>
Generate resources directories with my filtered resources using standard Maven
Resources plugin:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>gen-la1-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/la1/resources</outputDirectory>
<filters>
<filter>${basedir}/src/main/properties/la1.properties</filter>
</filters>
</configuration>
</execution>
</plugin>
Now configure the karaf-maven-plugin with options that apply to all executions
(assuming all distributions contain the same features):
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<bootFeatures>
<feature>wrap</feature>
<feature>aries-blueprint</feature>
<feature>shell</feature>
<feature>shell-compat</feature>
<feature>feature</feature>
<feature>jaas</feature>
<feature>ssh</feature>
<feature>management</feature>
<feature>bundle</feature>
<feature>config</feature>
<feature>deployer</feature>
<feature>diagnostic</feature>
<feature>feature</feature>
<feature>instance</feature>
<feature>kar</feature>
<feature>log</feature>
<feature>package</feature>
<feature>service</feature>
<feature>system</feature>
<feature>my-custom-feature</feature>
</bootFeatures>
</configuration>
Now configure each execution for each archive :
<execution>
<id>gen-assembly-la1</id>
<phase>prepare-package</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<includeBuildOutputDirectory>false</includeBuildOutputDirectory>
<sourceDirectory>${project.build.directory}/la1/resources</sourceDirectory>
<workDirectory>${project.build.directory}/la1/assembly</workDirectory>
</configuration>
</execution>
The above generates and assembly in my target/la1/assembly using the resources
from target/la1/resources which was previously prepared by the Maven Resources
plugin.
Now configure generation of the archive:
<execution>
<id>package-la1</id>
<phase>package</phase>
<goals>
<goal>archive</goal>
</goals>
<configuration>
<archiveTarGz>true</archiveTarGz>
<archiveZip>false</archiveZip>
<targetServerDirectory>${project.build.directory}/la1/assembly</targetServerDirectory>
<targetFile>${project.artifactId}-${project.version}-la1</targetFile>
</configuration>
</execution>
This will generate the *-la1.tar.gz file using the Assembly files from
target/la1/assembly. Notice the targetFile property does not currently work,
but this would be the only change needed in the plugin code.
The rest is adding new executions for each variation of the custom distribution.
Best regards,
Alex soto
> On Apr 21, 2016, at 2:04 PM, Alex Soto <[email protected]> wrote:
>
> Thanks, that will solve only one part of of the problem. The other part is
> how to tell the Assembly Mojo where to read resources from. Since I want
> to generate two archives with different properties, I am generating two
> separate directories using the Maven Resources plugin (in combination with
> filtering). So I will have two directories that I want the Assembly Mojo to
> use instead of the default. The Assembly Mojo has:
>
> // Include project classes content
> if (includeBuildOutputDirectory)
> IoUtils.copyDirectory(new
> File(project.getBuild().getOutputDirectory()), workDirectory);
>
> So it is hard coded to copy the target/classes directory; there is no way to
> tell it to look somewhere else.
> By comparison, the ArchiveMojo does have a property you can use to override
> its source dir:
>
> /**
> * The location of the server repository.
> */
> @Parameter(defaultValue="${project.build.directory}/assembly")
> private File targetServerDirectory;
>
> which is great, because I can have multiple versions of the assembly
> directory for different executions of the plugin.
> To support multiple executions, I think the Assembly Mojo needs to be able
> to read from different paths. Would this be possible?
>
> Best regards,
> Alex soto
>
>
>
>> On Apr 21, 2016, at 1:30 PM, Jean-Baptiste Onofré <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> Yes it's something that we can extend.
>>
>>
>> -------- Original message --------
>> From: Alex Soto <[email protected] <mailto:[email protected]>>
>> Date: 21/04/2016 18:23 (GMT+00:00)
>> To: [email protected] <mailto:[email protected]>
>> Subject: Re: karaf-maven-plugin multiple outputs with classifiers
>>
>> I found this fragment:
>>
>>
>> if (targetFile != null &&
>> project.getPackaging().equals("karaf-assembly")) {
>> serverName = targetFile.getName();
>> } else {
>> serverName = artifact.getArtifactId() + "-" +
>> artifact.getVersion();
>> }
>>
>> Means that target file is only honored when the pom packaging is
>> ‘karat-assembly’ which greatly limits the plugin.
>> Is there any strong reason for this? Why not honor the targetFile property
>> in all cases?
>>
>>
>> Best regards,
>> Alex soto
>>
>>
>>
>>> On Apr 21, 2016, at 12:56 PM, Morgan Hautman <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> Hi Alex,
>>>
>>> Take a look at the code here
>>> https://github.com/apache/karaf/tree/master/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling
>>>
>>> <https://github.com/apache/karaf/tree/master/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling>
>>>
>>> There is an "AssemblyMojo" & a ArchiveMojo (the 2 ones you use).
>>>
>>> There are all the parameters defined for a specific goal, with sometimes
>>> some comments on the parameter.
>>>
>>> I hope this help you clarify it a bit.
>>>
>>> Regards,
>>> Morgan
>>>
>>> PS: JB is away (travel) so he may not immediately respond if you need his
>>> knowledge.
>>>
>>> On 2016-04-21 17:10, Alex Soto wrote:
>>>> Not having any luck here!!
>>>>
>>>> Changed pom packaging to ‘pom’ and configured both goals ‘assembly’ and
>>>> ‘archive’ as separate executions:
>>>>
>>>> <plugin>
>>>> <groupId>org.apache.karaf.tooling</groupId>
>>>> <artifactId>karaf-maven-plugin</artifactId>
>>>> <executions>
>>>> <execution>
>>>> <id>gen-assembly-la1</id>
>>>> <phase>prepare-package</phase>
>>>> <goals>
>>>> <goal>assembly</goal>
>>>> </goals>
>>>> <configuration>
>>>> <classifier>la1</classifier>
>>>>
>>>> <resourcesDir>${project.build.directory}/la1/resources</resourcesDir>
>>>>
>>>> <targetServerDirectory>${project.build.directory}/la1/assembly</targetServerDirectory>
>>>>
>>>>
>>>> Both the <resourcesDir> and <targetServerDirectory> are ignored.
>>>>
>>>> Then on the archive goal:
>>>>
>>>> <execution>
>>>> <id>package-la1</id>
>>>> <phase>package</phase>
>>>> <goals>
>>>> <goal>archive</goal>
>>>> </goals>
>>>> <configuration>
>>>>
>>>> <classifier>la1</classifier>
>>>>
>>>> <archiveTarGz>true</archiveTarGz>
>>>>
>>>> <archiveZip>false</archiveZip>
>>>>
>>>> <targetFile>${project.artifactId}-${project.version}-la1</targetFile>
>>>> </configuration>
>>>> </execution>
>>>>
>>>> It also ignores the <targetFile> configuration. This should’t be that
>>>> hard, what’s going on? Any help?
>>>>
>>>> Best regards,
>>>> Alex soto
>>>>
>>>>
>>>>> On Apr 20, 2016, at 4:14 PM, Alex Soto <[email protected]
>>>>> <mailto:[email protected]>> wrote:
>>>>>
>>>>> Is there a good example? The one in the Karaf documentation page does
>>>>> not address this scenario, which is not uncommon; usually you will need
>>>>> different settings for each environment (DEV, TEST, UAT, PROD, etc.,) so
>>>>> cloning the project is not a practical approach. I tried with profiles
>>>>> but that too is not very practical, since you have build the same project
>>>>> multiple times, and the resulting archives are not deployed correctly to
>>>>> the Maven repository.
>>>>>
>>>>>
>>>>>> On Apr 20, 2016, at 11:03 AM, Alex Soto <[email protected]
>>>>>> <mailto:[email protected]>> wrote:
>>>>>>
>>>>>> Thank you JB,
>>>>>>
>>>>>> Which goal should I use?
>>>>>>
>>>>>>
>>>>>> Best regards,
>>>>>> Alex Soto
>>>>>>
>>>>>>
>>>>>>> On Apr 20, 2016, at 10:18 AM, Jean-Baptiste Onofré <[email protected]
>>>>>>> <mailto:[email protected]>> wrote:
>>>>>>>
>>>>>>> Hi Alex
>>>>>>>
>>>>>>> Using execution with the goal should do the trick (instead of just
>>>>>>> plugin definition).
>>>>>>>
>>>>>>> Regards
>>>>>>> JB
>>>>>>>
>>>>>>>
>>>>>>> -------- Original message --------
>>>>>>> From: Alex Soto <[email protected] <mailto:[email protected]>>
>>>>>>> Date: 20/04/2016 15:19 (GMT+01:00)
>>>>>>> To: [email protected] <mailto:[email protected]>
>>>>>>> Subject: karaf-maven-plugin multiple outputs with classifiers
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am trying (unsuccessfully) to us the 'karaf-maven-plugin’ to generate
>>>>>>> multiple archives from the same pom, using classifiers and executions.
>>>>>>>
>>>>>>> I have something like this:
>>>>>>>
>>>>>>>
>>>>>>> <plugin>
>>>>>>> <groupId>org.apache.karaf.tooling</groupId>
>>>>>>> <artifactId>karaf-maven-plugin</artifactId>
>>>>>>> <configuration>
>>>>>>> <bootFeatures>
>>>>>>> <feature>wrap</feature>
>>>>>>> <feature>aries-blueprint</feature>
>>>>>>> <feature>shell</feature>
>>>>>>> <feature>shell-compat</feature>
>>>>>>> <feature>feature</feature>
>>>>>>> <feature>jaas</feature>
>>>>>>> <feature>ssh</feature>
>>>>>>> <feature>management</feature>
>>>>>>> <feature>bundle</feature>
>>>>>>> <feature>config</feature>
>>>>>>> <feature>deployer</feature>
>>>>>>> <feature>diagnostic</feature>
>>>>>>> <feature>feature</feature>
>>>>>>> <feature>instance</feature>
>>>>>>> <feature>kar</feature>
>>>>>>> <feature>log</feature>
>>>>>>> <feature>package</feature>
>>>>>>> <feature>service</feature>
>>>>>>> <feature>system</feature>
>>>>>>> </bootFeatures>
>>>>>>> </configuration>
>>>>>>> <executions>
>>>>>>> <execution>
>>>>>>> <id>la1</id>
>>>>>>> <configuration>
>>>>>>> <classifier>la1</classifier>
>>>>>>> <resourcesDir>${project.build.outputDirectory}/la1</resourcesDir>
>>>>>>> </configuration>
>>>>>>> </execution>
>>>>>>> <execution>
>>>>>>> <id>la2</id>
>>>>>>> <configuration>
>>>>>>> <classifier>la2</classifier>
>>>>>>> <resourcesDir>${project.build.outputDirectory}/la2</resourcesDir>
>>>>>>> </configuration>
>>>>>>> </execution>
>>>>>>> </executions>
>>>>>>> </plugin>
>>>>>>>
>>>>>>>
>>>>>>> The difference between the two archives is in the resources, so I am
>>>>>>> specifying different ‘resourcesDir’ paths for each. The list of boot
>>>>>>> features will be the same for both executions, so I put it in the
>>>>>>> general configuration section of the plugin.
>>>>>>>
>>>>>>> When built, I am only getting a single archive output.
>>>>>>> Is it possible to do this with the 'karaf-maven-plugin’ plugin?
>>>>>>>
>>>>>>> Best regards,
>>>>>>> Alex soto
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>
>>
>