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

Hope to add SetProjectPropertiesMojo #102

Open
loeveol opened this issue Jun 1, 2023 · 0 comments
Open

Hope to add SetProjectPropertiesMojo #102

loeveol opened this issue Jun 1, 2023 · 0 comments

Comments

@loeveol
Copy link

loeveol commented Jun 1, 2023

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" ));  
    }
}
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

No branches or pull requests

1 participant