1010import org .apache .maven .plugins .annotations .LifecyclePhase ;
1111import org .apache .maven .plugins .annotations .Mojo ;
1212import org .apache .maven .plugins .annotations .Parameter ;
13+ import org .apache .maven .project .MavenProject ;
1314
1415import java .io .File ;
1516import java .nio .file .Path ;
@@ -28,21 +29,18 @@ public class ProcessMojo extends AbstractMojo {
2829 @ Parameter (required = true )
2930 private String id ;
3031
31- @ Parameter (required = false )
32- private String processorName ;
33-
34- @ Parameter (required = false )
32+ @ Parameter (required = true )
3533 private File apiPath ;
3634
3735 @ Parameter (required = false )
3836 private Options options ;
3937
40- @ Parameter (readonly = true , required = true , defaultValue = "${project.basedir }" )
41- private File baseDir ;
38+ @ Parameter (readonly = true , required = true , defaultValue = "${project}" )
39+ private MavenProject project ;
4240
4341 @ Override
4442 public void execute () throws MojoExecutionException {
45- String processor = String .format ("openapi-processor-%s" , processorName == null ? id : processorName );
43+ String processor = String .format ("openapi-processor-%s" , id );
4644
4745 try {
4846 getLog ().info (String .format ("%10s - %s" , "processor" , processor ));
@@ -53,7 +51,8 @@ public void execute () throws MojoExecutionException {
5351 String relativeSource = stripBaseDir (source .getAbsolutePath ());
5452 getLog ().info (String .format ("%10s - ${project.basedir}/%s" , "apiPath" , relativeSource ));
5553
56- String targetDir = (String ) properties .get (TARGET_DIR );
54+ String targetDir = (String ) properties .computeIfAbsent (TARGET_DIR , k -> project .getBuild ().getDirectory () + "/generated-sources/" + id );
55+ project .addCompileSourceRoot (targetDir );
5756 String relativeTargetDir = stripBaseDir (targetDir );
5857 getLog ().info (String .format ("%10s - ${project.basedir}/%s" , "targetDir" , relativeTargetDir ));
5958
@@ -79,7 +78,7 @@ public void execute () throws MojoExecutionException {
7978 }
8079
8180 private String stripBaseDir (String source ) {
82- Path base = Paths .get (baseDir .getAbsolutePath ());
81+ Path base = Paths .get (project . getBasedir () .getAbsolutePath ());
8382 Path src = Paths .get (source );
8483 return base .relativize (src ).toString ();
8584 }
0 commit comments