Maven 2 Ant Tasks - MavenDependency Script


/ Published in: Groovy
Save to your folder(s)

The base MavenDependency Script


Copy this code and paste it in your HTML
  1. class MavenDependency {
  2. static void require(params) {
  3. MavenDependencyHelper.getInstance().require(params)
  4. }
  5. static MavenDependencyHelper using(classLoader) {
  6. MavenDependencyHelper.getInstance(classLoader)
  7. }
  8. }
  9.  
  10. private class MavenDependencyHelper {
  11. private classLoader
  12. private MavenDependencyHelper(classLoader) {
  13. this.classLoader = classLoader
  14. }
  15.  
  16. static MavenDependencyHelper getInstance(classLoader) {
  17. return new MavenDependencyHelper(classLoader)
  18. }
  19.  
  20. static MavenDependencyHelper getInstance() {
  21. return new MavenDependencyHelper(MavenDependencyHelper.classLoader)
  22. }
  23.  
  24. MavenDependencyHelper require(params) {
  25. def ant = new AntBuilder()
  26. def mvn = groovy.xml.NamespaceBuilder.newInstance(ant, 'antlib:org.apache.maven.artifact.ant')
  27. mvn.dependencies(filesetId:"artifact_${params.groupId}_${params.artifactId}_${params.version}") { dependency(params) }
  28. ant.fileScanner { fileset(refid:"artifact_${params.groupId}_${params.artifactId}_${params.version}") }.each {
  29. classLoader.addClasspath(it.toString())
  30. }
  31. }
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.