Thanks Brett

That worked brilliantly.

regards

Stephen

Brett Porter wrote:

Sorry, it still needs an eclosing <dependencies>.

- Brett

On 11/22/05, Stephen Cowx <[EMAIL PROTECTED]> wrote:
Hi Brett

In regard to your second solution below:

I tried it out, but I get a parse error when reading the POM
"unrecognised tag: 'dependency'"

I dont think the "dependency" tag is allowed within a plugin tag.

Have I misunderstood your solution?

Here is what I understood you to mean by "include my dependency inside the plugin 
declaration"

<build>
   <plugins>
     <plugin>
       <groupId>com.group.id</groupId>
       <artifactId>plugin-sqlrunner</artifactId>
       <version>1.0.0-dev</version>
       <dependency>
         <groupId>ojdbc</groupId>
         <artifactId>ojdbc</artifactId>
         <version>14</version>
       </dependency>
       <executions>
         <execution>
           <phase>test</phase>
           <configuration>
              <user>${db-username}</user>
              <pass>${db-password}</pass>
              <url>${db-url}</url>
              <driver>oracle.jdbc.OracleDriver</driver>
              <onerror>continue</onerror>
              <files>
                <file>${basedir}/src/main/oracle/BillImage.sql</file>
                <file>${basedir}/src/main/oracle/RunTimeControls.sql</file>
                <file>${basedir}/src/main/oracle/audit.sql</file>
                <file>${basedir}/src/main/oracle/CreateSequences.sql</file>
              </files>
           </configuration>
           <goals>
             <goal>runsql</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
   </plugins>
 </build>


Stephen



Brett Porter wrote:

Two ways to solve this:

- have the user specify which dependency to use via configuration:
<plugin>
...
<configuration>
<jdbcDriver>com.mysql:mysql-driver</jdbcDriver>
</configuration>
</plugin>
...
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-driver</artifactId>
<version>5.0.0</version>
</dependency>

- add the dependency to the plugin declaration and just use the
current classloader (probably the best)
<plugin>
...
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-driver</artifactId>
<version>5.0.0</version>
</dependency>
</plugin>

Cheers,
Brett

On 11/21/05, Stephen Cowx <[EMAIL PROTECTED]> wrote:


Hi

I would like to take this one step further, I need to obtain the details
for a single dependency declared in a pom and use it in my plugin:

My plugin, which runs SQL scripts, needs to reference the JDBC driver of
the plugin users choice.

I need to be able to put the jar file containing this users chosen
driver onto the classpath that my plugin is using at runtime.
- I don't want to break the isolation that my plugin has from the other
dependencies in the users pom, I just need the jdbc driver.
- I don't want to have to specify the jdbc driver as a dependency for my
own plugin because I want lots of people to be able to use this with
lots of different drivers.

The only way I can think of to do this is to follow the steps outlined
in this thread for obtaining a list of artifacts for the pom using the
plugin, iterate through the list until I find the one the user has
specified to be their jdbc driver (through a property of some kind) and
then add that to the classpath being used by my plugin.

Although possible, this is a little unwieldy and I can;t help feeling
there must be an easy way to do this.

So...

Is there an existing way to do this, something like my example below
(note <dependency> property)

<build>
  <plugins>
    <plugin>
      <groupId>my.group.id</groupId>
      <artifactId>plugin-sqlrunner</artifactId>
      <version>1.0.0-dev</version>
      <executions>
        <execution>
          <phase>test</phase>
          <configuration>
                <user>${db-username}</user>
             <pass>${db-password}</pass>
             <url>${db-url}</url>
             <driver>oracle.jdbc.OracleDriver</driver>
             <onerror>continue</onerror>
             <dependency>
                 <groupId>ojdbc</groupId>
                 <artifactId>ojdbc</artifactId>
                 <version>14</version>
             <dependency>
             <files>
               <file>${basedir}/src/main/oracle/BillImage.sql</file>
               <file>${basedir}/src/main/oracle/RunTimeControls.sql</file>
               <file>${basedir}/src/main/oracle/audit.sql</file>
               <file>${basedir}/src/main/oracle/CreateSequences.sql</file>
             </files>
          </configuration>
          <goals>
            <goal>runsql</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>


regards

Stephen

Wim Deblauwe wrote:



ok, thanks! That was it.

2005/11/21, Allison, Bob <[EMAIL PROTECTED]>:




The tag "@requiresDependencyResolution" has to be on the class, not the
parameter.

-----Original Message-----
From: Wim Deblauwe [mailto:[EMAIL PROTECTED]
Sent: Monday, November 21, 2005 06:41
To: Maven Users List
Subject: Re: [m2] Copy the dependencies of a project in a custom plugin


The collection of artifacts is empty. When I was using dependencies, it
was
not empty. What am I doing wrong? This is my code:

/**
* @goal process-resources
* @description Copy the dependencies for the InstallShield Merge Module
*/
public class MsmProcessResourcesMojo extends AbstractMojo
{
/**
* @parameter expression="${project.artifacts}"
* @requiresDependencyResolution
*/
private Collection artifacts;

/**
* @parameter expression="${project.build.directory}/resources"
*/
private File targetDirectory;

public MsmProcessResourcesMojo()
{
}

public void execute() throws MojoExecutionException,
MojoFailureException
{
try
{
getLog().info( "Process Resources for InstallShield Merge Module..." );
Iterator iterator = artifacts.iterator();
while (iterator.hasNext())
{
Artifact artifact = (Artifact)iterator.next();
FileUtils.copyFileToDirectory( artifact.getFile(), new File(
targetDirectory, artifact.getType() + "s" ) );
}
}
catch (IOException e)
{
throw new MojoExecutionException( "Error copying artifacts", e );
}
}
}

thank you,

Wim

2005/11/21, Brett Porter <[EMAIL PROTECTED]>:




maven-artifact and maven-project (though you may not need the project
dependency if you are just using the expression below as it is
runtime, and Mavne provides it).

- Brett

On 11/21/05, Wim Deblauwe <[EMAIL PROTECTED]> wrote:




What dependency do I need for the Artifact and Project classes in my




Mojo?




2005/11/21, Brett Porter <[EMAIL PROTECTED]>:




On 11/21/05, Wim Deblauwe <[EMAIL PROTECTED]> wrote:




Hi,

I'm writing a custom plugin and I need to copy the project's




dependencies


from the local repository to a certain directory. How can I do


this




best?

You should use ${project.artifacts} instead which includes all the
transitive artifacts, and for which you can call




artifact.getFile().




Make sure you include @requiresDependencyResolution





question 2:
When my plugin works, it will produce a different artifact




(.msm),




how




should I handle the 'instal' and 'deploy' of that artifact? Do I




need to




write my own custom mojo for that or can I re-use the plugins




already




written for .jar files?




You can reuse the mojos, but you will still need to define the
customisations, which will require a plugin. There are examples in




the




"introduction to the build lifecycle".

Cheers,
Brett






---------------------------------------------------------------------




To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to