private void addClassesToClasspath ( UnpackedLibHelper helper , MavenProject project , Artifact artifact ) throws MavenExecutionException { // Work out where the dep will be extracted and calculate the file path to the classes jar. // This is location where the GenerateSourcesMojo will extract the classes. final File classesJar = helper . getUnpackedClassesJar ( artifact ) ; log . debug ( "Adding to classpath : " + classesJar ) ; // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. if ( ! classesJar . exists ( ) ) { classesJar . getParentFile ( ) . mkdirs ( ) ; try { final ZipOutputStream zipOutputStream = new ZipOutputStream ( new FileOutputStream ( classesJar ) ) ; zipOutputStream . putNextEntry ( new ZipEntry ( "dummy" ) ) ; zipOutputStream . close ( ) ; log . debug ( "Created dummy " + classesJar . getName ( ) + " exist=" + classesJar . exists ( ) ) ; } catch ( IOException e ) { throw new MavenExecutionException ( "Could not add " + classesJar . getName ( ) + " as dependency" , e ) ; } } // Modify the classpath to use an extracted dex file. This will overwrite // any exisiting dependencies with the same information. final Dependency dependency = createSystemScopeDependency ( artifact , classesJar , null ) ; final Dependency providedJar = findProvidedDependencies ( dependency , project ) ; if ( providedJar != null ) { project . getModel ( ) . removeDependency ( providedJar ) ; } project . getModel ( ) . addDependency ( dependency ) ; }
Add the dependent library classes to the project classpath .