当前位置: 首页 > 知识库问答 >
问题:

Eclipse使用旧的PATH变量在Gradle任务中执行命令行进程?

百里嘉泽
2023-03-14

我使用Gradle Exec任务。它执行命令行进程。我要执行的命令是:

pod install 

它需要安装cocoapods。我做到了。我使用pod--version从命令行检查它是否有效。输出是最新版本,即0.37.2。我的系统是OS X,我使用最新的Eclipse Luna版本。

我创建了一个自定义Gradle任务:

class InstallPodTask extends DefaultTask {

      @InputDirectory File srcDir

      @TaskAction
      def pod() {

        def xcodeProjectDir = // the dir the pod command is executed in

        try {
           project.exec {
              workingDir xcodeProjectDir
              executable "pod"
              args "install"
           }   
        } catch (Exception exception) { 

        }

     }
}

当我从命令行使用这个任务时,它可以正常工作。

当任务在Eclipse中执行时,就会出现问题。我使用eclipse的gradle插件。从eclipse运行上述任务时,我出现以下错误:

CocoaPods要求终端使用UTF-8编码。考虑将以下内容添加到~/。配置文件中:

WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:

export LANG=en_US.UTF-8
[0m
[!] Unable to load a specification for the plugin `/Library/Ruby/Gems/2.0.0/gems/cocoapods-plugins-0.4.1`
[!] Unable to load a specification for the plugin `/Library/Ruby/Gems/2.0.0/gems/cocoapods-try-0.4.3`
[!] Unable to load a specification for the plugin `/Library/Ruby/Gems/2.0.0/gems/cocoapods-trunk-0.6.0`
[!] The version of CocoaPods used to generate the lockfile (0.37.2) is higher than the version of the current executable (0.36.0). Incompatibility issues may arise.
Analyzing dependencies
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/lib/cocoapods/user_interface/error_report.rb:119:in ``': No such file or directory - git (Errno::ENOENT)
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/lib/cocoapods/user_interface/error_report.rb:119:in `git_information'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/lib/cocoapods/user_interface/error_report.rb:38:in `report'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/lib/cocoapods/command.rb:59:in `report_error'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.8.1/lib/claide/command.rb:374:in `handle_exception'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.8.1/lib/claide/command.rb:315:in `rescue in run'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.8.1/lib/claide/command.rb:303:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/lib/cocoapods/command.rb:46:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.36.0/bin/pod:44:in `<top (required)>'
    from /usr/bin/pod:23:in `load'
    from /usr/bin/pod:23:in `<main>'

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':j2objcXcode'.
> Process 'command 'pod'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.91 secs
[sts] Build failed
org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-bin.zip'.
    at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:57)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
    at org.gradle.tooling.internal.consumer.DefaultBuildLauncher.run(DefaultBuildLauncher.java:71)
    at org.springsource.ide.eclipse.gradle.core.TaskUtil.execute(TaskUtil.java:117)
    at org.springsource.ide.eclipse.gradle.core.launch.GradleProcess$1.doit(GradleProcess.java:92)
    at org.springsource.ide.eclipse.gradle.core.util.GradleRunnable$1.run(GradleRunnable.java:53)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':j2objcXcode'.
    at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:77)
    at org.gradle.initialization.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
    at org.gradle.initialization.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:30)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:108)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:54)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    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:120)
    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':j2objcXcode'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:310)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    ... 34 more
Caused by: org.gradle.process.internal.ExecException: Process 'command 'pod'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:365)
    at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:31)
    at org.gradle.api.internal.file.DefaultFileOperations.exec(DefaultFileOperations.java:154)
    at org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:787)
    at org.gradle.api.internal.project.AbstractProject.exec(AbstractProject.java:783)
    at org.gradle.api.Project$exec$4.call(Unknown Source)
    at com.github.j2objccontrib.j2objcgradle.tasks.J2objcXcodeTask.pod(J2objcXcodeTask.groovy:154)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:243)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:230)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 57 more
[sts] Time taken: 0 min, 5 sec
[sts] -----------------------------------------------------

错误说:

用于生成锁文件的CocoaPods版本(0.37.2)高于当前可执行文件的版本(0.36.0)。

这很奇怪,当我从终端运行pod-version时,我得到了version0.37.2。

为什么在eclipse中运行的任务与从终端运行时的行为不同?eclipse使用不同的命令行吗?


共有2个答案

苍宝
2023-03-14

从pod安装中删除锁文件(在命令提示符下运行时创建),然后使用eclipse再次运行。命令行进程生成的锁文件使用CocoaPods(0.37.2),而eclipse使用CocoaPods(0.36.0)插件安装pod。如果您需要更多信息,请重新开始。

编辑:: 在运行pod install之前使用rm-rf MyProject.xcworkspace

虞滨海
2023-03-14

您需要在更改任何系统环境变量后重新启动Eclipse。

 类似资料:
  • 你可以用命令行选项-x来排除某些任务,让我们用上面的例子来示范一下. 例子 11.2. 排除任务 gradle dist -x test 命令的输出 > gradle dist -x test :compile compiling source :dist building the distribution BUILD SUCCESSFUL Total time: 1 secs 可以看到, tes

  • 你可以以列表的形式在命令行中一次调用多个任务. 例如 gradle compile test 命令会依次调用 compile 和 test 任务, 它们所依赖的任务也会被调用. 这些任务只会被调用一次, 无论它们是否被包含在脚本中:即无论是以命令行的形式定义的任务还是依赖于其它任务都会被调用执行.来看下面的例子. 下面定义了四个任务 dist和test 都 依赖于 compile ,只用当 com

  • 当你试图调用某个任务的时候, 你并不需要输入任务的全名. 只需提供足够的可以唯一区分出该任务的字符即可. 例如, 上面的例子你也可以这么写. 用 gradle di 来直接调用 dist 任务: 例 11.3. 简化任务名 gradle di 命令的输出 > gradle di :compile compiling source :compileTest compiling unit tests

  • 我的Gradle项目使用了KotlinDSL和JUnit5/Jupiter(以及Kotlin作为编程语言),Gradle似乎没有正确地接受我的任何测试。当我在命令行上运行Gradle测试时,它告诉我 不管我怎么尝试。然而,在我的IDE中,我可以轻松地运行项目中的每个单个测试类,而不会出现任何问题。

  • 我试图找到从命令行传递gradle任务参数的最佳方法。我有这个任务。我想从学生练习中解包解决方案,并将它们复制到项目中的正确位置,以突出它们。我这样称呼这个任务: 这是gradle任务: 你有什么建议来优化这个过程吗?

  • 主要内容:执行预置 Maven 命令,执行自定义 Maven 命令在 Eclipse 中新建和导入 Maven 项目后,接下来就可以执行 Maven 命令对这些项目进行构建了。当然,您依然可以在命令行中执行 Maven 命令进行构建,不过本节将介绍如何在 Eclipse 中直接执行 Maven 命令。 执行预置 Maven 命令 在项目或其 pom.xml 上单击鼠标右键,选择 Run As 选项,就能够看到如图 1 的菜单。 图1:Eclipse 预置 Mav