Search code examples
javamavenelasticsearchxjcmaven-jaxb2-plugin

How to add custom repository to maven-jaxb2-plugin


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


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>