------ Sharing Resources ------ Dennis Lundberg ------ 2011-02-05 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. Sharing Resources The Remote Resources Plugin can also be used to share resources between modules in a multi module build. In the following example we have a set of files that are used to set up a test environment for a database. We want to reuse these resources in several modules in our project. * Set up a module for the resources to be shared Create a new module called <<>>. Put the files in a directory layout like the one below, making sure that your resource files are in the <<>> directory: ------------------- shared-resources | +- src | | | `- main | | | `- resources | | | +- database.ddl | | | `- database.sql | `- pom.xml ------------------- The POM for <<>> should look like this: ------------------- ... org.test shared-resources ... maven-remote-resources-plugin ${project.version} bundle **/*.ddl **/*.sql ... ------------------- This will bundle the shared resources in a JAR file during the <<>> phase. This means that others modules can consume these resources in any phase after that. * Configure other modules to use the shared module To use the shared resources in another module you need to configure the plugin as follows: ------------------- ... org.test resource-consumer ... org.apache.maven.plugins maven-remote-resources-plugin ${project.version} org.test:shared-resources:\${project.version} process ... org.codehaus.mojo sql-maven-plugin 1.4 ... ... create-schema process-test-resources execute true \${project.build.directory}/maven-shared-archive-resources/database.ddl \${project.build.directory}/maven-shared-archive-resources/database.sql ... ... \${project.groupId} shared-resources \${project.version} ------------------- This will retrieve the bundled resources of the <<>> module, process each resource in the bundle and put them in the <<<\${project.build.directory}/shared-resources>>> directory of the <<>> module. That means we can use those files in the SQL Maven Plugin to set up the database schema using a DDL file, and add some data to the database using an SQL file.