The org.apache.maven.bridge package is not currently exposed to plugins from 
maven-core (see importMavenApi in DefaultClassRealmManager) which is why you 
get an exception trying to access it.

Could you use the org.apache.maven.repository.RepositorySystem component 
instead? This would also be more portable since the MavenRepositorySystem 
component was only recently added in 3.2.3

-- 
Cheers, Stuart


On Monday, 6 October 2014 at 12:31, Arnaud Derasse wrote:

> Hello all,
> 
> --------------------------
> -- Short Version --
> --------------------------
> I am tryting to access MavenRepositorySystem from my mojo to
> call buildArtifactRepository()
> When executing the goal, I have a ClassDefNotFound error :
> 
> [WARNING] Error injecting:
> com.enyx.maven.plugin.enyx_maven_plugin.EnyxValidate
> java.lang.NoClassDefFoundError:
> Lorg/apache/maven/bridge/MavenRepositorySystem;
> at java.lang.Class.getDeclaredFields0(Native Method)
> at java.lang.Class.privateGetDeclaredFields(Class.java:2436)
> at java.lang.Class.getDeclaredFields(Class.java:1806)
> at
> com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:661)
> [....]
> Caused by: java.lang.ClassNotFoundException:
> org.apache.maven.bridge.MavenRepositorySystem
> at
> org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
> at
> org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
> 
> [...]
> [ERROR] Failed to execute goal
> com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate
> (default-validate) on project libenyxcom: Execution default-validate of
> goal com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate
> failed: A required class was missing while executing
> com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate:
> Lorg/apache/maven/bridge/MavenRepositorySystem;
> 
> 
> I am using Maven 3.2.3, the class IS in the maven-core-3.2.3.jar in my lib/
> dir of my maven install.
> I do not understand why I :
> -> Can't inject the MavenRepositorySystem instance.
> -> Can't even use the static function buildArtifactRepository() from
> MavenRepositorySystem, if I remove this from my mojo class :
> @Component
> private MavenRepositorySystem repoSystem;
> I still get a Class not found error like this :
> 
> [INFO] --- enyx-maven-plugin:0.0.3-SNAPSHOT:validate (default-validate) @
> libenyxcom ---
> [INFO] Detected Host System : Debian - Unknown
> [ERROR] This version of your Host Platform does not have Deployment
> Information
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 1.111 s
> [INFO] Finished at: 2014-10-06T13:24:43+02:00
> [INFO] Final Memory: 7M/152M
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] Failed to execute goal
> com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate
> (default-validate) on project libenyxcom: Execution default-validate of
> goal com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate
> failed: A required class was missing while executing
> com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT:validate:
> org/apache/maven/bridge/MavenRepositorySystem
> [ERROR] -----------------------------------------------------
> [ERROR] realm =
> plugin>com.enyx.maven.plugins:enyx-maven-plugin:0.0.3-SNAPSHOT
> [ERROR] strategy =
> org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
> [ERROR] urls[0] =
> file:/home/derassea/.m2/repository/com/enyx/maven/plugins/enyx-maven-plugin/0.0.3-SNAPSHOT/enyx-maven-plugin-0.0.3-SNAPSHOT.jar
> [ERROR] urls[1] =
> file:/home/derassea/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar
> [ERROR] urls[2] =
> file:/home/derassea/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar
> [ERROR] urls[3] =
> file:/home/derassea/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar
> [ERROR] urls[4] =
> file:/home/derassea/.m2/repository/com/google/guava/guava/10.0.1/guava-10.0.1.jar
> [ERROR] urls[5] =
> file:/home/derassea/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
> [ERROR] urls[6] =
> file:/home/derassea/.m2/repository/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar
> [ERROR] urls[7] =
> file:/home/derassea/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
> [ERROR] urls[8] =
> file:/home/derassea/.m2/repository/org/eclipse/sisu/org.eclipse.sisu.inject/0.0.0.M5/org.eclipse.sisu.inject-0.0.0.M5.jar
> [ERROR] urls[9] =
> file:/home/derassea/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
> [ERROR] urls[10] =
> file:/home/derassea/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.3/maven-plugin-annotations-3.3.jar
> [ERROR] urls[11] =
> file:/home/derassea/.m2/repository/com/googlecode/cmake-maven-project/cmake-maven-plugin/2.8.11-b4/cmake-maven-plugin-2.8.11-b4.jar
> [ERROR] urls[12] =
> file:/home/derassea/.m2/repository/org/eclipse/aether/aether-util/0.9.0.M2/aether-util-0.9.0.M2.jar
> [ERROR] urls[13] =
> file:/home/derassea/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.16/plexus-interpolation-1.16.jar
> [ERROR] urls[14] =
> file:/home/derassea/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
> [ERROR] urls[15] =
> file:/home/derassea/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
> [ERROR] urls[16] =
> file:/home/derassea/.m2/repository/com/google/code/findbugs/annotations/2.0.1/annotations-2.0.1.jar
> [ERROR] urls[17] =
> file:/home/derassea/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.18/plexus-utils-3.0.18.jar
> [ERROR] urls[18] =
> file:/home/derassea/.m2/repository/org/twdata/maven/mojo-executor/2.2.0/mojo-executor-2.2.0.jar
> [ERROR] urls[19] =
> file:/home/derassea/.m2/repository/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar
> [ERROR] Number of foreign imports: 1
> [ERROR] import: Entry[import from realm
> ClassRealm[project>com.enyx.libs:libenyxcom:1.9.1-SNAPSHOT, parent:
> ClassRealm[maven.api, parent: null]]]
> [ERROR]
> [ERROR] -----------------------------------------------------:
> org.apache.maven.bridge.MavenRepositorySystem
> 
> -------------------------------
> ----- Long Version -----
> -------------------------------
> If some of you are wondering WHY I am trying to access
> MavenRepositorySystem from a mojo , the answer is bellow :
> -> I am building a plugin to manage a C++/CMake build and deploy lifecycle
> -> I need to publish to a Nexus repository, various packaged artifacts,
> resulting from the build
> -> Depending on the system running maven, the artifacts will be different (
> .deb on Debian based systems, .rpm on RPM based ... )
> -> I need to publish these artifacts to the RIGHT nexus repo, depending on
> the OS flavour ( RedHat/Debian ) and version ( el5, el6, el7 ; ubuntu,
> debian6 ,debian7)
> 
> To do this, I was first thinking to use Profiles... activated on Property.
> For this, I created a mojo acting during the VALIDATE phase to populate two
> properties on the project :
> project.getProperties().setProperty("linuxDistribution",
> linuxType.toString());
> project.getProperties().setProperty("linuxDistributionVersion",
> distroVersion );
> 
> BUT ... I discovered that the profiles were activated before my validate
> goal was called... So the property doesnt exists...
> This is why I am trying to set the project.setReleaseArtifactRepository(
> repoRelease ); and project.setSnapshotArtifactRepository( repoRelease ); by
> hand. For this I need the buildArtifactRepository function to be accessed.
> 
> If someone have any idea to achieve what I want to do, with the minimum of
> maven internals hacking, I will be glad.
> Maybe there's a way to extend Maven Profiles Activation, so that I can
> activate the right profile depending on which Linux Distribution maven is
> currently running.
> the <os> tag is a good idea, but Version is equal to the kernel version for
> Linux, which is not good for what I want to do.
> Maybe I can introduce new tags... to get Distribution (RedHat , Debian )
> and Version ( el5, el6, el7)
> and use them for Profie activation.
> 
> Any help welcome
> 
> 
> Best Regards
> 
> Arnaud Derasse 

Reply via email to