wso2-extensions / archetypes

Apache License 2.0
2 stars 32 forks source link

Double execution of the "car" goal from maven-car-plugin #34

Closed gspadotto closed 4 days ago

gspadotto commented 5 months ago

Description: The following lines in the CompositeExporter archetype cause the "package" phase to be executed twice: https://github.com/wso2-extensions/archetypes/blob/master/esb-project-archetype/src/main/resources/archetype-resources/__rootArtifactId__CompositeExporter/pom.xml#L77-L85

This is because the "car" goal from maven-car-plugin is already configured for the "package" phase in the default lifecycle: https://github.com/wso2/maven-tools/blob/v5.2.34/maven-car-plugin/src/main/resources/META-INF/plexus/components.xml#L35

Suggested Labels: bug

Suggested Assignees: pamodaaw

Affected Product Version: From 2.0.17: https://github.com/wso2-extensions/archetypes/commit/09c63836a242e730e2ea15b158aa6707d3e01a72#diff-99ecab20addd5e5942e6a7616a1883a3f5e7c504c9849f5cf7b4ec25d01f6556

Steps to reproduce:

Generate an Integration Project, move to the XXXXCompositeApplication folder, run:

mvn package

See that the "car" goal is executed twice, once with (default-car) and once with (car).

Alternatively, execute from the same folder the following command:

mvn buildplan:list

And see that the output is like the one below:

[INFO] Build Plan for .....CompositeApplication: 
--------------------------------------------------------------------------------------------------
PHASE                  | PLUGIN                  | VERSION | GOAL          | EXECUTION ID         
--------------------------------------------------------------------------------------------------
process-resources      | maven-resources-plugin  | 3.3.1   | resources     | default-resources    
compile                | maven-compiler-plugin   | 3.13.0  | compile       | default-compile      
process-test-resources | maven-resources-plugin  | 3.3.1   | testResources | default-testResources
test-compile           | maven-compiler-plugin   | 3.13.0  | testCompile   | default-testCompile  
test                   | maven-surefire-plugin   | 3.2.5   | test          | default-test         
package                | maven-car-plugin        | 2.1.1   | car           | default-car          
package                | maven-car-plugin        | 2.1.1   | car           | car                  
install                | maven-install-plugin    | 3.1.1   | install       | default-install      
deploy                 | maven-car-deploy-plugin | 1.1.1   | deploy-car    | default-deploy-car   
deploy                 | maven-deploy-plugin     | 3.1.1   | deploy        | default-deploy   

Related Issues: https://github.com/wso2/maven-tools/pull/118

DedunuKarunarathne commented 4 months ago

Hi @gspadotto,

We will analyze the bug and get back to you as soon as possible.

Best regards, Dedunu

gspadotto commented 1 month ago

Hi @DedunuKarunarathne did you have enough time for your analysis? Any news?

IsuruMaduranga commented 1 month ago

Hi @gspadotto,

Do you use Integration Studio or Archetype to generate your project? If it's through Integration Studio, we may need to apply a fix to the Studio's Java code. Otherwise, we can consider making adjustments directly to the archetype.

Thanks, Isuru

gspadotto commented 1 month ago

Hi @IsuruMaduranga, I use maven to build the artefacts within a CI/CD pipeline. Doesn't Integration Studio use the same archetypes/plugins "behind the curtains", so to say?

GDLMadushanka commented 1 month ago

Hi @gspadotto,

Integration Studio does not use this archetype. It generates the pom file using JAVA. We can fix the issue in both Integration Studio and archetype. But I'm afraid it will take some time to release an update for the Integration Studio.

Thanks, Lahiru

IsuruMaduranga commented 1 month ago

Hi @gspadotto,

Until we release an updated version, you can bypass the described issue by temporarily disabling the following XML block in the CompositeExporter pom.xml:

<executions>
    <execution>
        <id>car</id>
            <phase>package</phase>
            <goals>
              <goal>car</goal>
            </goals>
    </execution>
</executions>

To facilitate this modification in a CI/CD pipeline, I've prepared a sample shell script that automates the process. Please feel free to adjust it according to your needs:

#!/bin/bash

# Define the file path
FILE_PATH="pom.xml"

# Check if xmlstarlet is installed
if ! command -v xmlstarlet &> /dev/null
then
    echo "xmlstarlet could not be found. Please install it to run this script."
    exit 1
fi

# Check if the file exists
if [ ! -f "$FILE_PATH" ]; then
    echo "File not found: $FILE_PATH"
    exit 1
fi

# Backup the original file
cp $FILE_PATH "${FILE_PATH}.bak"

# Command to remove the specific executions block
xmlstarlet ed -N x="http://maven.apache.org/POM/4.0.0" \
    -d "//x:project/x:build/x:plugins/x:plugin[x:artifactId='maven-car-plugin']/x:executions/x:execution[x:id='car']" \
    $FILE_PATH > $FILE_PATH.mod

# Check for modifications and replace the original file if changes have been made
if cmp -s "$FILE_PATH" "$FILE_PATH.mod"
then
    echo "No changes made."
    rm "$FILE_PATH.mod"
else
    mv "$FILE_PATH.mod" "$FILE_PATH"
    echo "Executions block removed successfully."
fi

Thank you, Isuru

gspadotto commented 1 month ago

Hi @IsuruMaduranga thank you for the provided script!

Please refer to this issue in the PR that will fix it so that we can get notifications.