[ 
http://jira.codehaus.org/browse/MDEP-213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=221929#action_221929
 ] 

Jim Sellers commented on MDEP-213:
----------------------------------

As a work around I created a groovy script that will that:
1) take the pom, copy it to the target directory
2) remove the dependencyManagement tags so that the pom just has dependencies
3) run dependency:resolve on that modified pom, failing the build if 
dependency:resolve fails.

In the pom:
{noformat}
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.groovy.maven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              
<source>${pom.basedir}/src/main/script/resolveDepMgmt.groovy</source>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
{noformat}

The contents of resolveDepMgmt.groovy is:
{noformat}
import org.apache.commons.lang.SystemUtils

log.info('About to run check on the dependency management section...')

// read the pom, remove the dependencyManagement tags
File sourceFile = new File('pom.xml')
String text = sourceFile.text.replaceAll('<dependencyManagement>', 
'').replaceAll('</dependencyManagement>', '')

// make the outputDirectory if it does not exist 
File outputDir = new File('target')
if (!outputDir.exists())
        outputDir.mkdirs()

File ouputFile = new File(outputDir.getAbsolutePath() + 
'/pom-only-dependencies.xml')
ouputFile.write(text)

String mvnCommand = "mvn dependency:resolve -f " + ouputFile.getAbsolutePath()

// because mvn is not an executable program on windows
if (SystemUtils.IS_OS_WINDOWS)
        mvnCommand = 'cmd /c ' + mvnCommand

outputCatcher = new StringBuffer()
errorCatcher = new StringBuffer()
proc = mvnCommand.execute()
proc.consumeProcessOutput(outputCatcher, errorCatcher)
proc.waitFor()

// print the output / errors to the screen
println outputCatcher

// have the calling process share the exit value of the maven command if there 
was an error
if (0 != proc.exitValue())
        fail('failed resolving dependencies')
{noformat}

> resolve dependencyManagement section with option to fail the build
> ------------------------------------------------------------------
>
>                 Key: MDEP-213
>                 URL: http://jira.codehaus.org/browse/MDEP-213
>             Project: Maven 2.x Dependency Plugin
>          Issue Type: New Feature
>          Components: resolve
>    Affects Versions: 2.0
>            Reporter: Jim Sellers
>            Assignee: Brian Fox
>
> When using the dependencyManagement section of a pom of type "pom" to create 
> a bill of materials, it's currently possible to specify an invalid version.  
> eg:
> {code:xml}
>       <dependencyManagement>
>               <dependencies>
>                       <dependency>
>                               <groupId>commons-logging</groupId>
>                               <artifactId>commons-logging</artifactId>
>                               <version>9.9</version>
>                       </dependency>
>               </dependencies>
>       </dependencyManagement>
> {code} 
> It would be really useful for these types of pom's to be able to force all 
> the dependencies to be resolved when running something like "install" and 
> have that fail the build.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to