How to resolve dependency between files generated by maven plugin at compile time?

487 views Asked by At

Ok, let me try to put my problem across as less confusing as I can.

I have a standard maven project with a few Maven plugins -

1) maven-antrun-plugin
2) Custom maven plugin, say, my-maven-plugin
3) jaxws-maven-plugin

Now here's the complicated part.

The 1st plugin generates a few .java files which I'm currently placing in "${project.build.directory}/java"

The 2nd plugin generates another set of .java files all of which I'm placing again under "${project.build.directory}/java". However, they're placed under different package structures.

Both of these plugins run during the "generate-sources" phase.

Now my 3rd plugin, jaxws-maven-plugin, tries to use the class files for the files generated by 1st and 2nd plugins, as the SEI to generate WSDLs. But the class files won't be created by maven at that point during the compilation and the plugin errors out with a "Class Not found" message.

So how do I go about trying to resolve this? Also, since I error out during the "generate-sources" phase, I don't see the .class files for any of the other source files from my project in the target/classes directory.

And oh, here's another twist. Some of my source files import these compile time generated source files in the code (You have no idea how badly I'm searching for this developer right now!!)

I have tried to describe my problem in the best possible way so please feel free to ask any other details or clarifications.

1

There are 1 answers

0
Radio Rogal On

Run manually build-helper-maven-plugin and maven-compile-plugin before jaxws-maven-plugin:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            ...
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                </execution>
                ...
            </executions>
        <plugin>
        <plugin>
            ...
            <artifactId>my-maven-plugin</artifactId>
            ...
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                </execution>
                ...
            </executions>
        <plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>some directory</source>
                            ...
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compile-plugin</artifactId>
            ...
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                </execution>
                <goals>
                    <goal>compile</goal>
                </goals>
            </executions>
        <plugin>
        <plugin>
            <artifactId>jaxws-maven-pluginn</artifactId>
            ...
        <plugin>

    </plugins>
</build>

I haven't tested it but I think it should work.