为什么Maven生成的源代码没有被编译?

acs*_*404 27 java maven-3 maven

我有一个插件,可以在target/generated-sources/wrappers目录下生成源代码.它连接到generate-sources阶段,如下所示:

<plugin>
    <groupId>mygroupid</groupId>
    <artifactId>myartifactid</artifactId>
    <executions>
        <execution>
        <phase>generate-sources</phase>
        <goals>
            <goal>xml2java</goal>
        </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

问题是,当我使用mvn deploy.class文件不会被放置在罐子.我看到.java那里的所有文件,但没有.class.

我阅读了有关此问题的所有问题,但无法弄清楚如何解决问题.我正在使用Maven 3.0.x.

acs*_*404 59

build-helper插件确实解决了这个问题.感谢@Joe的评论.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated-sources/wrappers</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)


Mar*_*ner 11

如果您自己编写了插件,则可以以编程方式将生成的源的路径添加到maven源路径.

@Mojo(name = "generate")
public class MyCodegenMojo extends AbstractMojo {
    @Parameter(defaultValue = "${project}")
    private MavenProject project;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException{
        // your generator code

        project.addCompileSourceRoot("path/to/your/generated/sources");
    }

}
Run Code Online (Sandbox Code Playgroud)

例如,raml-jaxrs-codegen插件使用这种技术.有关更多详细信息,请参阅RamlJaxrsCodegenMojo.java.