Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin fails to run. #16

Open
kec2 opened this issue Mar 28, 2017 · 8 comments
Open

Plugin fails to run. #16

kec2 opened this issue Mar 28, 2017 · 8 comments

Comments

@kec2
Copy link

kec2 commented Mar 28, 2017

I can't get your plugin to work

Gradle version 3.4
Java 7 64bit
Windows 7 64Bit

Build.gradle

plugins {
  id "com.github.sherter.google-java-format" version "0.6"
}

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7

javadoc.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    mavenCentral()
}

This is the gradle error:

C:\Users\kec\workspace_neon> gradlew goJF

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\kec\workspace_neon\build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'com.github.sherter.google-java-format', version: '0.6']
> Failed to apply plugin [id 'com.github.sherter.google-java-format']
   > Could not create an instance of type com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension_Decorated.

Exception stacktrace:

* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.github.sherter.google-java-format', version: '0.6']
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:224)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:171)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$000(LifecycleProjectEvaluator.java:33)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:53)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:50)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:599)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:125)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
        at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuildAction.execute(DefaultGradleLauncher.java:233)
        at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuildAction.execute(DefaultGradleLauncher.java:230)
        at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:160)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        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:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:31)
        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:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
        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.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        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:72)
        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.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.github.sherter.google-java-format']
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:155)
        at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:112)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$5.run(DefaultPluginRequestApplicator.java:174)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:212)
        ... 61 more
Caused by: org.gradle.internal.reflect.ObjectInstantiationException: Could not create an instance of type com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension_Decorated.
        at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:52)
        at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
        at org.gradle.api.internal.plugins.DefaultConvention.create(DefaultConvention.java:103)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatPlugin.createExtension(GoogleJavaFormatPlugin.groovy:47)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatPlugin.apply(GoogleJavaFormatPlugin.groovy:34)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatPlugin.apply(GoogleJavaFormatPlugin.groovy)
        at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
        at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:139)
        ... 64 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -5
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension$_defaultInputs_closure1.doCall(GoogleJavaFormatExtension.groovy:32)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:70)
        at org.gradle.util.ConfigureUtil.configureTarget(ConfigureUtil.java:160)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:106)
        at org.gradle.api.internal.project.DefaultProject.configure(DefaultProject.java:960)
        at org.gradle.api.internal.project.DefaultProject.configure(DefaultProject.java:965)
        at org.gradle.api.internal.project.DefaultProject.allprojects(DefaultProject.java:946)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension.defaultInputs(GoogleJavaFormatExtension.groovy:31)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension.<init>(GoogleJavaFormatExtension.groovy:26)
        at com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormatExtension_Decorated.<init>(Unknown Source)
        at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:50)
        ... 72 more
@sherter
Copy link
Owner

sherter commented Mar 28, 2017

I don't have access to a windows 7 machine right now, but I'll increase the priority of issue #10 on my TODO list (I couldn't reproduce the problem on Linux, OpenJDK 7, Gradle 3.4)

@sherter
Copy link
Owner

sherter commented Mar 31, 2017

I re-tried on windows 7, but couldn't reproduce the problem:

C:\Users\admin\Desktop>java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

C:\Users\admin\Desktop>gradle -version

 ------------------------------------------------------------
Gradle 3.4
------------------------------------------------------------

Build time:   2017-02-20 14:49:26 UTC
Revision:     73f32d68824582945f5ac1810600e8d87794c3d4

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.7.0_80 (Oracle Corporation 24.80-b11)
OS:           Windows 7 6.1 amd64

C:\Users\admin\Desktop>gradle goJF
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --statu
s for details
:googleJavaFormat NO-SOURCE

BUILD SUCCESSFUL

Total time: 6.241 secs
C:\Users\admin\Desktop>

I also tried with Java 8 and didn't have any problems.
Could you provide more details? Does it always produce this error?

PS: I don't understand why I have to create an Oracle account in order to download Java 7... ugh!

@kec2
Copy link
Author

kec2 commented Apr 3, 2017

I can't reproduce this problem today. I have tried two projects (one of which failed last week) and it works fine.

@sherter sherter closed this as completed Apr 3, 2017
@sherter sherter added the invalid label Apr 3, 2017
@mcs6502
Copy link

mcs6502 commented Jan 16, 2018

I had the same failure with google-java-format-gradle-plugin version 0.6 on Win10 with jdk8. The "String index out of range" at GoogleJavaFormatExtension.groovy:32 could occur if your projects don't share the same parent directory. This can happen, for example, if you are using dependency substitution in your Gradle project, and replacing some of your modules with projects that reside in a parent directory outside your current project. For me the workaround was to avoid using dependency substitution in my build.gradle while running this plugin's tasks.

@mcs6502
Copy link

mcs6502 commented Jan 19, 2018

The expression at GoogleJavaFormatExtension.groovy:32 "p.buildDir.path.substring(project.projectDir.path ..." may produce unexpected results if one project is not nested within another. This could happen, for example, due to Gradle dependency substitution, if you replace a module with a project in a parent directory.
For me the workaround was to temporarily stop using dependency substitution in my build.gradle while I was running this plugin.

@sherter
Copy link
Owner

sherter commented Mar 6, 2018

@mcs6502 Thanks for the detailed analysis (and sorry for the delay). I've never used dependency substitution before. Do you have an example project at hand?

@sherter sherter reopened this Mar 6, 2018
@sherter sherter removed the invalid label Mar 7, 2018
@cdennison
Copy link

Same issue here - I get the same String index out of range error when defining a Gradle dependency in a separate folder.

This didn't work:

build.gradle
dependencies {
    compile project(":common")
    ...
}

settings.gradle
include ':common'
project(':common').projectDir = new File('../common')

The fix was to comment out the projectDir which isn't great because now it won't build so I have to comment, verify, uncomment, build.

settings.gradle
include ':common'
//project(':common').projectDir = new File('../common')

@DwordPtr
Copy link

I'm experiencing this issue today on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants