문제

I am mavenizing an ant project. One module includes XSD files that are used to generate source files using Castor. I have everything working if I run:

mvn castor:generate package

However I am not able to get it to run the generate goal for my plugin without specifying it on the command line. My plugin xml section is as follows:

<plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>castor-maven-plugin</artifactId>
      <version>1.0</version>
      <configuration>
      </configuration>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
</plugin>

I have tried a number of phase entries without any luck. Any idea what I am doing wrong here? I have tested this in Windows XP and Linux, using Maven 2 and 3. I have tried it with version 1.0 (which I must use) and 2.0 of the castor-maven-plugin.

Thanks Tim

도움이 되었습니까?

해결책

The castor:generate goal is bound by default to the lifecycle phase generate-sources so you don't even have to bind it explicitly unless you want to bind it to another phase of course.

Assuming your *.xsd are in the default directory src/main/castor, the following would thus be enough:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>castor-maven-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <!--schema>src/main/castor/schema.xsd</schema-->
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

And assuming you have a src/main/castor/castorbuilder.properties file, here is the output when invoking a phase posterior to the generate-sources phase:

$ mvn package [INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Q4169367/ 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- castor-maven-plugin:1.0:generate (default) @ Q4169367 ---
[INFO] Processing /home/pascal/Projects/stackoverflow/Q4169367/src/main/castor/schema.xsd
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q4169367 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q4169367/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q4169367 ---
[INFO] Compiling 3 source files to /home/pascal/Projects/stackoverflow/Q4169367/target/classes
...

In other words, the version 1.0 of the plugin gets triggered as expected (version 2.0 works too). Tested with Maven 3.0.

If it doesn't for you, please provide a project allowing to reproduce and mention the goal you invoking.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top