无法使用BuildScopeServices.createScriptPluginFactory()

时间:2018-11-13 00:54:17

标签: gradle

我正在使用IntelliJ,并且能够通过GUI来构建和运行Gradle项目,方法是按下播放按钮,然后从终端运行此命令

./gradlew --stacktrace deploy

产生此控制台输出,并且构建失败:

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.internal.service.ServiceCreationException: Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:816)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.create(DefaultServiceRegistry.java:767)
        at org.gradle.internal.service.DefaultServiceRegistry$ManagedObjectServiceProvider.getInstance(DefaultServiceRegistry.java:571)
        at org.gradle.internal.service.DefaultServiceRegistry$SingletonService.get(DefaultServiceRegistry.java:628)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.assembleParameters(DefaultServiceRegistry.java:780)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.create(DefaultServiceRegistry.java:766)
        at org.gradle.internal.service.DefaultServiceRegistry$ManagedObjectServiceProvider.getInstance(DefaultServiceRegistry.java:571)
        at org.gradle.internal.service.DefaultServiceRegistry$SingletonService.get(DefaultServiceRegistry.java:628)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.assembleParameters(DefaultServiceRegistry.java:780)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.create(DefaultServiceRegistry.java:766)
        at org.gradle.internal.service.DefaultServiceRegistry$ManagedObjectServiceProvider.getInstance(DefaultServiceRegistry.java:571)
        at org.gradle.internal.service.DefaultServiceRegistry$SingletonService.get(DefaultServiceRegistry.java:628)
        at org.gradle.internal.service.DefaultServiceRegistry.find(DefaultServiceRegistry.java:295)
        at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:284)
        at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:279)
        at org.gradle.initialization.DefaultGradleLauncherFactory.doNewInstance(DefaultGradleLauncherFactory.java:179)
        at org.gradle.initialization.DefaultGradleLauncherFactory.newInstance(DefaultGradleLauncherFactory.java:108)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:40)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:61)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:34)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:46)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.internal.service.ServiceCreationException: Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:816)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.create(DefaultServiceRegistry.java:767)
        at org.gradle.internal.service.DefaultServiceRegistry$ManagedObjectServiceProvider.getInstance(DefaultServiceRegistry.java:571)
        at org.gradle.internal.service.DefaultServiceRegistry$SingletonService.get(DefaultServiceRegistry.java:628)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.assembleParameters(DefaultServiceRegistry.java:780)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryService.create(DefaultServiceRegistry.java:766)
        at org.gradle.internal.service.DefaultServiceRegistry$ManagedObjectServiceProvider.getInstance(DefaultServiceRegistry.java:571)
        at org.gradle.internal.service.DefaultServiceRegistry$SingletonService.get(DefaultServiceRegistry.java:628)
        at org.gradle.internal.service.DefaultServiceRegistry.find(DefaultServiceRegistry.java:295)
        at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:284)
        at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:279)
        at org.gradle.internal.service.scopes.BuildScopeServices.defaultScriptPluginFactory(BuildScopeServices.java:301)
        at org.gradle.internal.service.scopes.BuildScopeServices.createScriptPluginFactory(BuildScopeServices.java:293)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.internal.service.ReflectionBasedServiceMethod.invoke(ReflectionBasedServiceMethod.java:35)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:814)
        ... 61 more
Caused by: org.gradle.api.GradleException: Could not generate a proxy class for class org.gradle.plugin.management.internal.DefaultPluginResolutionStrategy.
        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:228)
        at org.gradle.api.internal.AbstractClassGenerator.generate(AbstractClassGenerator.java:80)
        at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
        at org.gradle.plugin.internal.PluginUsePluginServiceRegistry$BuildScopeServices.createPluginResolutionStrategy(PluginUsePluginServiceRegistry.java:106)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.internal.service.ReflectionBasedServiceMethod.invoke(ReflectionBasedServiceMethod.java:35)
        at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:814)
        ... 79 more
Caused by: java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
        at org.gradle.internal.classloader.ClassLoaderUtils.define(ClassLoaderUtils.java:104)
        at org.gradle.model.internal.asm.AsmClassGenerator.define(AsmClassGenerator.java:58)
        at org.gradle.model.internal.asm.AsmClassGenerator.define(AsmClassGenerator.java:54)
        at org.gradle.api.internal.AsmBackedClassGenerator$ClassBuilderImpl.generate(AsmBackedClassGenerator.java:967)
        at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:226)
        ... 88 more

13 个答案:

答案 0 :(得分:7)

曾经使用过Java 11,后来改用Java 8了。

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
./gradlew --stacktrace deploy

答案 1 :(得分:2)

在项目根目录运行这个find ./ -name "*.lock" -type f -delete

答案 2 :(得分:2)

我也遇到过类似的情况。我所要做的就是在项目目录上运行 chmod 777 .gradle/。您可能需要使用 sudo

答案 3 :(得分:1)

我通过删除来解决此问题 .gradle / checksums / checksums.lock

和所有* .lock文件:(

答案 4 :(得分:1)

就我而言,我只是打开Android Studio并打开了项目的文件夹,然后Android Studio自动更新了所有Gradle依赖项。我不使用Android Studio进行编码(我使用VSC),但是在此之后,我可以运行该项目。

答案 5 :(得分:0)

是的,通过在preoject目录中运行以下命令从Java 11切换到较低版本时,它可以工作...

export JAVA_HOME = /usr/libexec/java_home -v 1.8

答案 6 :(得分:0)

问题确实来自Java 11,但是与升级到Java 10之后的版本名称问题类似,可以通过升级Gradle来解决此问题。 Gradle 5.5中不存在该问题,但我不确定最早支持哪个版本。 (在撰写本文时,5.5是Gradle的最新版本)

如果您正在使用每个项目的Gradle包装器(带有gradle/wrapper/gradle-wrapper.properties),您要做的就是更改包含分发URL的行,并更改版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-bin.zip

答案 7 :(得分:0)

我使用的是远程Jenkins,堆栈跟踪的开始与此问题类似,但是根本原因是无法创建.gradle

dir如堆栈跟踪所示:

Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/var/lib/jenkins/jobs/APPNAME/workspace/COMPANY/Android/APPNAME/.gradle' when creating directory '/var/lib/jenkins/jobs/APPNAME/workspace/COMPANY/Android/APPNAME/.gradle/4.6/fileHashes'
at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:272)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:58)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:34)
at org.gradle.cache.internal.DefaultCacheFactory.doOpen(DefaultCacheFactory.java:92)
at org.gradle.cache.internal.DefaultCacheFactory.open(DefaultCacheFactory.java:66)
at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.open(DefaultCacheRepository.java:124)
at org.gradle.api.internal.changedetection.state.CrossBuildFileHashCache.<init>(CrossBuildFileHashCache.java:41)
at org.gradle.internal.service.scopes.BuildSessionScopeServices.createCrossBuildFileHashCache(BuildSessionScopeServices.java:194)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.internal.service.ReflectionBasedServiceMethod.invoke(ReflectionBasedServiceMethod.java:35)
at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:855)  

我发现它试图建立的目录由root用户拥有,但Jenkins与jenkins用户一起运行。我通过chown用户的目录来解决此问题。

答案 8 :(得分:0)

我使用的是 4.3.3版,当我运行Jenkinsfile管道并发运行且运行给定管道时,就会出现此问题 parallel在N上运行单个Gradle任务。 stages部分中的Gradle项目。

parallel阶段stages部分删除script部分不会导致此-或我在下面的帖子中列出的其他怪异问题-或-您只需在管道的管道运行(即非并行运行)上运行即可。

有关我的管道作业/面临的问题,请参见此处。

Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits & Gradle error: Task 'null' not found in root project

答案 9 :(得分:0)

在我的IntelliJ 运行配置中,我只是忘记填充Gradle Project字段-填充该字段后即可构建。

enter image description here

答案 10 :(得分:0)

  • 在资源管理器中的表演中打开您的项目
  • 选择您的项目文件夹,然后转到属性
  • 然后进入安全性,然后授予访问权限或读取和写入权限
  • 基本上检查您的项目文件夹是否已锁定,如果已锁定(要写入),则授予写入权限

答案 11 :(得分:0)

在将 Android Studio libgdx 游戏库一起使用时,我遇到了这个问题...

就我而言,我进行了File > Invalidate Caches / Restart...,还单击了Invalidate and Restart操作并解决了...

答案 12 :(得分:0)

对我有用的解决方案(React native)。转到 .gradle 文件夹并搜索子目录中的所有 .lock 文件并将其全部删除。之后运行命令 gradlew clean,然后使用命令 react-native run-android 运行您的项目。

我还下载了一个gradle6.6因为有人从我的系统路径中删除了它。