DataNucleus JDO and Maven(2+)

Apache Maven is a project management and build tool that is quite common in organisations. Using DataNucleus and JDO with Maven is simple since the DataNucleus jars, JDO API jar and DataNucleus Maven plugin are present in the Maven central repository, so you don't need to define any repository to find the artifacts.

The only remaining thing to do is identify which artifacts are required for your project, updating your pom.xml accordingly.

<project>
    ...
    <dependencies>
        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0</version>
        </dependency>
    </dependencies>
    ...
</project>

The only distinction to make here is that the above is for compile time since your persistence code (if implementation independent) will only depend on the basic persistence API. At runtime you will need the DataNucleus artifacts present also, so this becomes

<project>
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>[3.0, 3.0.99)</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <version>[3.0, 3.0.99)</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    ...
</project>

Obviously replace the datanucleus-rdbms jar with the jar for whichever datastore you are using.

Please note that from DataNucleus AccessPlatform 3.0.4 onwards you can alternatively use the convenience artifact for JDO+RDBMS (or JDO+ whichever datastore you're using).

<project>
    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-accessplatform-jdo-rdbms</artifactId>
            <version>3.0.4</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    ...
</project>


Maven2 Plugin : Enhancement and SchemaTool

Now that you have the DataNucleus jars available to you, via the repositories, you want to perform DataNucleus operations. The primary operations are enhancement and SchemaTool. If you want to use the DataNucleus Maven plugin for enhancement or SchemaTool add the following to your pom.xml

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <api>JDO</api>
                    <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
                    <verbose>true</verbose>
                    <props>${basedir}/datanucleus.properties</props>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Note that this plugin step will automatically try to bring in the latest applicable version of datanucleus-core for use by the enhancer. It does this since you don't need to have datanucleus-core in your POM for compilation/enhancement. If you want to use an earlier version then you need to add exclusions to the maven-datanucleus-plugin

The executions part of that will make enhancement be performed immediately after compile, so automatic. See also the Enhancer docs

To run the enhancer manually you do

mvn datanucleus:enhance
                

DataNucleus SchemaTool is achieved similarly, via

mvn datanucleus:schema-create