0

Is it possible to use a defined parameter in another parameter? For example I tried this and figured out this is not allowed:

@Parameter(required = true)
private String semester;

@Parameter(defaultValue = "${basedir}/src/main/resources/" + semester)
private String inputFolder;

My second try was to put use the parameter as expression:

@Parameter(defaultValue = "${basedir}/src/main/resources/${semester}")
private String inputFolder;

This was also a fail. The next iteration: I wrote the parameter as property at plugin's execution:

@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
    Properties props = project.getProperties();
    props.put("semester", semester);
}

This doesn't work either, because the parameters are injected before execute() is executed. The only solution I get to is to replace the expressions by myself:

inputFolder = inputFolder.replace("${semester}", semester);
outputFolder = outputFolder.replace("${semester}", semester);
Danny Lo
  • 1,553
  • 4
  • 26
  • 48

1 Answers1

1

As you already discover: no, you can't reuse it like this. The code suggest that there's a variable folder for a semester (do you really need to reuse it?). That's kind of weird: just point the inputDirectory to the correct folder, make that parameter required. Less obvious solution is to do it in code:

File semesterFolder = new File( inputFolder, semester);

Ensure that you document the parameters very well, like how the semester parameter is used to get this folder.

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44