Required class is missing: org/codehaus/gmaven/mojo/GroovyMojo when tried to run to generate report and send an email in the Maven Project

荒凉一梦 提交于 2019-12-13 17:01:40

问题


I have Maven JUnit Project, which compiles, builds and tests successfully. Also when I do the mvn site all the tests run successfully and generates the surefire-report at ..\target\site.. directory.

Now, I need to send an email this report to given recipients.

Here is my POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>xxxx</groupId>
<artifactId>EmailReportMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name></name>
<description></description>
 <dependencies>
  <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.12</version>
  </dependency>
  <dependency>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-report-plugin</artifactId>
     <version>2.18.1</version>
  </dependency>
  <dependency>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-site-plugin</artifactId>
     <version>3.6</version>
  </dependency>
  <dependency>
     <groupId>org.apache.maven.doxia</groupId>
     <artifactId>doxia-core</artifactId>
     <version>1.7</version>
  </dependency>
  <dependency>
     <groupId>ch.fortysix</groupId>
     <artifactId>maven-postman-plugin</artifactId>
     <version>0.1.6</version>
  </dependency>
 </dependencies>
<build>
  <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
           <source>1.7</source>
           <target>1.7</target>
        </configuration>
     </plugin>
     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.10</version>
        <executions>
           <execution>
              <id>add-source</id>
              <phase>generate-sources</phase>
              <goals>
                 <goal>add-source</goal>
              </goals>
              <configuration>
                 <sources>
                    <source>appmodels</source>
                 </sources>
              </configuration>
           </execution>
        </executions>
     </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
           <testFailureIgnore>false</testFailureIgnore>
        </configuration>
        <version>2.7.2</version>
     </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.18.1</version>
     </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.6</version>
        <configuration>
           <generateSitemap>true</generateSitemap>
           <generateReports>true</generateReports>
        </configuration>
     </plugin>
     <plugin>
        <groupId>ch.fortysix</groupId>
        <artifactId>maven-postman-plugin</artifactId>
        <version>0.1.6</version>
        <executions>
           <execution>
              <id>send_an_mail</id>
              <goals>
                 <goal>send-mail</goal>
              </goals>
              <inherited>false</inherited>
              <phase>test</phase>
              <configuration>
                 <from>mailID</from>
                 <subject>this is a test auto email sent from Eclipse using Maven</subject>
                 <htmlMessage><![CDATA[<p>Hi, Please find attached.</p>]]></htmlMessage>
                 <failonerror>true</failonerror>
                 <mailhost>host</mailhost>
                 <mailport>port</mailport>
                 <mailssl>true</mailssl>
                 <mailAltConfig>true</mailAltConfig>
                 <mailuser>emailID</mailuser>
                 <mailpassword>password</mailpassword>
                 <receivers>
                    <receiver>emailID</receiver>
                 </receivers>
                 <fileSets>
                    <fileSet>
                       <directory>${basedir}/target/site</directory>
                       <includes>
                          <include>**/surefire-report.html</include>
                       </includes>
                    </fileSet>
                 </fileSets>
              </configuration>
           </execution>
        </executions>
     </plugin>
  </plugins>
  <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
        <plugin>
           <groupId>org.eclipse.m2e</groupId>
           <artifactId>lifecycle-mapping</artifactId>
           <version>1.0.0</version>
           <configuration>
              <lifecycleMappingMetadata>
                 <pluginExecutions>
                    <pluginExecution>
                       <pluginExecutionFilter>
                          <groupId>org.codehaus.mojo</groupId>
                          <artifactId>build-helper-maven-plugin</artifactId>
                          <versionRange>[1.10,)</versionRange>
                          <goals>
                             <goal>add-source</goal>
                          </goals>
                       </pluginExecutionFilter>
                       <action>
                          <ignore />
                       </action>
                    </pluginExecution>
                 </pluginExecutions>
              </lifecycleMappingMetadata>
           </configuration>
        </plugin>
     </plugins>
  </pluginManagement>
 </build>
  <reporting>
  <plugins>
     <!-- Include the unit test reports in the site -->
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.18.1</version>
     </plugin>
  </plugins>

Below errors are thrown when mvn surefire-report:report postman:send-mail is run:

[INFO] --- maven-postman-plugin:0.1.6:send-mail (Report Generation) @ EmailReportMaven ---
[WARNING] Error injecting: ch.fortysix.maven.plugin.postaman.MailSenderMojo
java.lang.TypeNotPresentException: Type 
ch.fortysix.maven.plugin.postaman.MailSenderMojo not present
    at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:147)
    at org.eclipse.sisu.space.NamedClass.load(NamedClass.java:46)
    at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
    at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53)
    at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:65)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:115)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:133)
    at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68)
    at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:63)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45)
    at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
    at org.eclipse.sisu.inject.Guice4$1.get(Guice4.java:162)
    at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:81)
    at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:263)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:255)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:519)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.NoClassDefFoundError: org/codehaus/gmaven/mojo/GroovyMojo
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:139)
    ... 41 more
Caused by: java.lang.ClassNotFoundException: org.codehaus.gmaven.mojo.GroovyMojo
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    ... 70 more
 [INFO] ------------------------------------------------------------------------
 [INFO] BUILD FAILURE
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 24.073 s [INFO] Finished at:
 2017-07-05T18:47:50-05:00 [INFO] Final Memory: 28M/226M
 [INFO] ------------------------------------------------------------------------
 [ERROR] Failed to execute goal
 ch.fortysix:maven-postman-plugin:0.1.6:send-mail (Report Generation)
 on project EmailReportMaven: Execution Report Generation of goal
 ch.fortysix:maven-postman-plugin:0.1.6:send-mail failed: Unable to
 load the mojo 'send-mail' in the plugin
 'ch.fortysix:maven-postman-plugin:0.1.6'. A required class is missing:
 org/codehaus/gmaven/mojo/GroovyMojo
 [ERROR] -----------------------------------------------------
 [ERROR] realm =    plugin>ch.fortysix:maven-postman-plugin:0.1.6
 [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
 [ERROR] urls[0] =
 file:/C:/Development/Maven_Repo/ch/fortysix/maven-postman-plugin/0.1.6/maven-postman-plugin-0.1.6.jar
 [ERROR] urls[1] =
 file:/C:/Development/Maven_Repo/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
 [ERROR] Number of foreign imports: 1
 [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
 [ERROR]
 [ERROR] -----------------------------------------------------
 [ERROR] : org.codehaus.gmaven.mojo.GroovyMojo
 [ERROR] -> [Help 1]
 [ERROR]
 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
 [ERROR]
 [ERROR] For more information about the errors and possible solutions, please read the following articles:
 [ERROR] [Help 1]

回答1:


I was able to resolve this issue. I did the following things:

  1. Deleted the contents of the ../org/apache/maven folder.
  2. Deleted the contents of the ../ch/ folder (this was the turning point, I thought so)
  3. Re-built the Maven project.
  4. Ran mvn site command.
  5. Successfully e-mail sent with surefire-report.html as attachment.


来源:https://stackoverflow.com/questions/44935076/required-class-is-missing-org-codehaus-gmaven-mojo-groovymojo-when-tried-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!