Skip to content

Hope to add SetProjectPropertiesMojo #102

@loeveol

Description

@loeveol

I use properties-maven-plugin to load the configuration file through ReadPropertiesMojo in the pom to skip some plugins, but I need to use SetSystemPropertiesMojo to change the value of the property in the subproject without skipping.
I found that ReadPropertiesMojo writes properties to project.setProperties, but SetSystemPropertiesMojo writes properties to System.setProperties.
This leads to <skip>${xxxx}</skip> not being able to get properties correctly in the pom of the subproject.

So after verification, I wonder if the following Mojo can make this process more reasonable:
(My English is not good, the above is translated by machine, please understand)

@Mojo( name = "set-project-properties", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true )
public class SetProjectPropertiesMojo    extends AbstractMojo
{
    @Parameter( defaultValue = "${project}", readonly = true, required = true )
    private MavenProject project;
   
    @Parameter( required = true )
    private Properties properties;

    public void execute()
    {
        if ( properties.isEmpty() )
        {
            getLog().debug( "No project properties found" );

            return;
        }

        getLog().debug( "Setting project properties:" );

        Properties projectProperties = project.getProperties();

        for ( Enumeration<?> n = projectProperties.propertyNames(); n.hasMoreElements(); )
        {
            String k = (String) n.nextElement();

        }

        for ( Enumeration<?> propertyNames = properties.propertyNames(); propertyNames.hasMoreElements(); )
        {
            String propertyName = propertyNames.nextElement().toString();
            String propertyValue = properties.getProperty( propertyName );

            getLog().debug( "- " + propertyName + " = " + propertyValue );

            projectProperties.setProperty( propertyName, propertyValue );
        }
        int count = properties.size();

        getLog().info( "Set " + count + " project " + ( count > 1 ? "properties" : "property" ));  
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions