Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gspadotto opened this issue Mar 29, 2024 · 8 comments · Fixed by wso2/integration-studio#1351
Closed

Comments

@gspadotto
Copy link

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:
09c6383#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:
wso2/maven-tools#118

@DedunuKarunarathne
Copy link

Hi @gspadotto,

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

Best regards,
Dedunu

@gspadotto
Copy link
Author

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

@IsuruMaduranga
Copy link

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
Copy link
Author

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
Copy link

GDLMadushanka commented Aug 5, 2024

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
Copy link

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
Copy link
Author

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.

@gspadotto
Copy link
Author

@GDLMadushanka I would not close this issue as "complete" until these lines from the CompositeExporter archetype are removed:
https://github.com/wso2-extensions/archetypes/blob/master/esb-project-archetype/src/main/resources/archetype-resources/__rootArtifactId__CompositeExporter/pom.xml#L77-L85

The changes in wso2/integration-studio@2b9f7b5 only fix the problem when using Integration Studio.
When one uses maven, the workaround suggested by @IsuruMaduranga still needs to be applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants