You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by James Carpenter <jc...@yahoo.com> on 2006/06/27 04:41:51 UTC

How do I dynamically inject a dependency?

I have a plugin which resolves a specified artifact, expands it into a 
work area within target and then runs a code generator against contents 
within the expanded artifact.
{Specifically the resolved artifact contains an XML-Schema, and the tool 
being executed is a csharp xsd tool (similar to JAXB)}

The specified artifact is not an actual dependency of the plugin code, 
nor is it a compiler or testing dependency of the project.  That said 
the specified artifact is required to build the project and should be 
taken into account when maven determines a multi-project's build order.  
What can the plugin do to ensure maven is aware of this specified 
artifact as a build dependency, without affecting the dependencies seen 
by the other plugins (compiler, etc.)?

One potential solution I have used in the past is to include the 
specified artifact as a plugin dependency, but this is rather crude and 
doesn't work in the general case.

Example POM snipt below:

Example assumes the com.acme.serverapp:client-schema:${project.version} 
artifact contains the bigSchema.xml file.  The maven-codegen-plugin is 
assumed to perform the following steps:
1) resolve the specified artifact: 
com.acme.serverapp:client-schema:${project.version}
2) unpack it in ${basedir}/target/csharp-workarea/maven-codegen-plugin/
3) point a code generator at the bigSchema.xml file to produce source 
files in ${basedir}/target/generated-sources/maven-codegen-plugin
4) add the generated code to the MavenProject

<build>
<plugins>
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-codegen-plugin</artifact>
    <version>1.2.3</version>
   <configuration>
       <schemaDependency>
           <groupId>com.acme.serverapp</groupId>
            <artifactId>client-schema</artifactId>
             <version>${project.version}</version>
              <type>jar</type>  <!-- Could be any archive type. (tar, 
zip, gzip, etc.)-->
              
<schemaFile>com/acme/serverapp/schema/bigSchema.xml</schemaFile>
       </schemaDependency>
   </configuration>
</plugin>
</plugins>
</build>

Assume a multiproject structure such as:
acmecode/pom.xml
acmecode/client-schema/pom.xml
acmecode/client-schema/src/main/resources/com/acme/serverapp/schema/bigSchema.xml
acmecode/schema-stubs/pom.xml  #This is the pom using the plugin

As you can see, if one tries to perform a multi-module build within the 
acmecode directory, its shear luck if the build order is correct.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org