JavaでサンプルのMavenプロジェクトを作成していますが、目標でテストを指定するとこの例外が発生し、ビルドエラーが発生します。しかしclean
、compile
、test-compile
は正常に機能しています。つまり、ビルドは成功しましたが、test
を書き込むとエラーが発生します。これは初めてです。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building firstProject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ demo ---
[WARNING] The POM for org.Apache.maven.surefire:surefire-booter:jar:2.12.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.Apache.maven.surefire:maven-surefire-common:jar:2.12.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.Apache.maven.reporting:maven-reporting-api:jar:2.0.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.Apache.maven:maven-toolchain:jar:2.0.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.Apache.maven.plugin-tools:maven-plugin-annotations:jar:3.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Error injecting: org.Apache.maven.plugin.surefire.SurefirePlugin
Java.lang.TypeNotPresentException: Type org.Apache.maven.plugin.surefire.SurefirePlugin not present
at org.Eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.Java:115)
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:86)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.Java:54)
at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.Java:70)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.Java:115)
at org.Eclipse.sisu.bean.BeanScheduler$Activator.onProvision(BeanScheduler.Java:176)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.Java:126)
at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.Java:68)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.Java:68)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.Java:46)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.Java:1009)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.Java:1059)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.Java:1005)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.Java:36)
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:546)
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:153)
at org.Apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.Java:145)
at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:116)
at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.Java:80)
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:307)
at org.Apache.maven.DefaultMaven.doExecute(DefaultMaven.Java:193)
at org.Apache.maven.DefaultMaven.execute(DefaultMaven.Java:106)
at org.Apache.maven.cli.MavenCli.execute(MavenCli.Java:862)
at org.Apache.maven.cli.MavenCli.doMain(MavenCli.Java:286)
at org.Apache.maven.cli.MavenCli.main(MavenCli.Java:197)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:497)
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/Apache/maven/plugin/surefire/SurefireReportParameters
at Java.lang.ClassLoader.defineClass1(Native Method)
at Java.lang.ClassLoader.defineClass(ClassLoader.Java:760)
at Java.security.SecureClassLoader.defineClass(SecureClassLoader.Java:142)
at Java.net.URLClassLoader.defineClass(URLClassLoader.Java:467)
at Java.net.URLClassLoader.access$100(URLClassLoader.Java:73)
at Java.net.URLClassLoader$1.run(URLClassLoader.Java:368)
at Java.net.URLClassLoader$1.run(URLClassLoader.Java:362)
at Java.security.AccessController.doPrivileged(Native Method)
at Java.net.URLClassLoader.findClass(URLClassLoader.Java:361)
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:107)
... 42 more
Caused by: Java.lang.ClassNotFoundException: org.Apache.maven.plugin.surefire.SurefireReportParameters
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)
... 57 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.544 s
[INFO] Finished at: 2016-06-30T13:04:16+05:30
[INFO] Final Memory: 8M/110M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project demo: Execution default-test of goal org.Apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: Unable to load the mojo 'test' in the plugin 'org.Apache.maven.plugins:maven-surefire-plugin:2.12.4'. A required class is missing: org/Apache/maven/plugin/surefire/SurefireReportParameters
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.Apache.maven.plugins:maven-surefire-plugin:2.12.4
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/embed/.m2/repository/org/Apache/maven/plugins/maven-surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar
[ERROR] urls[1] = file:/home/embed/.m2/repository/org/Apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.jar
[ERROR] urls[2] = file:/home/embed/.m2/repository/org/Apache/maven/surefire/maven-surefire-common/2.12.4/maven-surefire-common-2.12.4.jar
[ERROR] urls[3] = file:/home/embed/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.8/plexus-utils-3.0.8.jar
[ERROR] urls[4] = file:/home/embed/.m2/repository/org/Apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
[ERROR] urls[5] = file:/home/embed/.m2/repository/org/Apache/maven/plugin-tools/maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.Apache.maven.plugin.surefire.SurefireReportParameters
[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] http://cwiki.Apache.org/confluence/display/MAVEN/PluginContainerException
私のpom.xml
ファイル:-
<project xsi:schemaLocation="http://maven.Apache.org/POM/4.0.0 http://maven.Apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>firstProject</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</project>
誰かが私が間違っているところを提案できますか?
Pom.xmlで次の依存関係を使用します。これはpom.xmlのプラグインです。
<build> <plugins> <plugin> <groupId>org.Apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
Mvnクリーンインストールを実行すると、intelliJを使用している場合は、mavenプロジェクトタブにsurefireプラグインが表示されるはずです。 Intellijを使用している場合のプラグインの表示方法のスクリーンショット
次に、intelliJでプロジェクトのMaven-> Reimportを実行します。これは問題を解決します、
<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>com.sample</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.Apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
このpom.xmlを使用して、mvnを試してテスト目標をインストールしてください。
以下はMavenライフサイクルコマンドです
検証、コンパイル、テスト、パッケージ、統合-テスト、検証、インストール、デプロイ
Intellijを使用している場合は、「オフラインモード」がチェックされている可能性があります。これにより、このエラーが発生します。チェックを外してください。
mvn -U clean install
私の問題を修正しました。それが基本的に ヨハン・グランルンド が指摘したことです