Question

I'm using a maven-jaxb2-plugin (org.jvnet.jaxb2.maven2) to generate resources and xjb bindings to add annotations to generated beans.

Those annotations have to be included into plugin's classpath so I'm using dependencies section.

If some of those dependencies missing in maven central build fails. How can I add repositories to look for into the plugin?

E.g. this artifact can't be found in maven central

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
    <version>1.0.0.M2</version>
</dependency>

But can be found in another repository:

<repository>
    <id>spring-libs-milestone</id>
    <name>Spring Milestone Repository</name>
    <url>http://repo.spring.io/libs-milestone</url>
</repository>

Plugin config:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.3</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${spring.data.mongodb.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>1.0.0.M2</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <strict>true</strict>
        <verbose>true</verbose>
        <extension>true</extension>
        <removeOldOutput>true</removeOldOutput>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <bindingDirectory>src/main/resources</bindingDirectory>
        <addCompileSourceRoot>true</addCompileSourceRoot>
        <args>
            <arg>-Xannotate</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics-annotate</artifactId>
                <version>0.6.3</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>0.6.3</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

Build example: http://azee.people.yandex.net/job/elastic-template/6/console

Source code: https://github.com/azee/elastic-template/tree/nodeps

Was it helpful?

Solution

You need to define a pluginRepository instead of a normal repository.

Plugins and all their dependencies are only resolved from pluginRepositories. This is to separate code and build dependencies.

So add:

<pluginRepositories>
  <pluginRepository>
    <id>spring-libs-milestone</id>
    <name>Spring Milestone Repository</name>
    <url>http://repo.spring.io/libs-milestone</url>
  </pluginRepository>
</pluginRepositories>

OTHER TIPS

Author of the maven-jaxb2-plugin as well as jaxb2-basics here. My recommendation would be to add your dependency as plugin into configuration rather that as dependency to the maven plugin.

See this test project:

    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <configuration>
                <extension>true</extension>
                <args>
                    <arg>-Xannotate</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics-annotate</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics-test-annox-annotations</artifactId>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>
    </plugins>

I believe this to be better than dependencies of the Maven plugin. First, I think the normal repo will used for the artifact resolution in this case. Next, at least in the times of Maven 2.x, Maven created just one instance of each maven plugin. So the first one in the build order defines the dependencies/classpath of the plugin. Providing the dependency artifact in the configuration does not have this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top