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

Can it work as a Gradle init script [Yes!] ? #253

Open
patkujawa-wf opened this issue Jan 4, 2022 · 7 comments
Open

Can it work as a Gradle init script [Yes!] ? #253

patkujawa-wf opened this issue Jan 4, 2022 · 7 comments
Assignees
Labels

Comments

@patkujawa-wf
Copy link

Is it possible to use this plugin as an init script?

I use https://github.com/ben-manes/gradle-versions-plugin#using-a-gradle-init-script for all my projects, which is very convenient and allows me to keep it out of each repo. I'd like to do the same for gradle-test-logger-plugin, but I'm running into "Plugin with id 'com.adarshr.test-logger' not found." when I mimic the instructions.

I've created a $HOME/.gradle/init.d/gradle-test-logger-plugin.gradle (similar to my current $HOME/.gradle/init.d/add-versions-plugin.gradle that's working) with these contents:

initscript {
    repositories {
        gradlePluginPortal()
        // maven {
        //     url 'https://plugins.gradle.org/m2/'
        // }
    }
    dependencies {
        classpath 'com.adarshr:gradle-test-logger-plugin:+'
    }
}

allprojects {
    apply plugin: 'com.adarshr.test-logger'
}

I've tried a few variations of repositories and using buildscript instead of initscript, but all end up with the same Plugin with id 'com.adarshr.test-logger' not found. failure.

@patkujawa-wf
Copy link
Author

Another example which works until I can get this sweet plugin to work is in https://stackoverflow.com/questions/45856846/how-can-i-share-build-code-script-for-all-my-gradle-projects-not-just-subprojec

allprojects {
    tasks.withType(Test) {
        testLogging {
            events "passed", "skipped", "failed", "standardOut", "standardError"
        }
    }
}

@radarsh
Copy link
Owner

radarsh commented Jan 16, 2022

That's odd but there is nothing different about the way the plugin is published. Have you tried running with info or debug log level turned on to perhaps get some clue? Could you also try with a specific version such as 3.1.0 instead of the + wildcard to see if it works?

@patkujawa-wf
Copy link
Author

Aha, it was an issue with trying to use the plugin id, which apparently isn't supported in init scripts.

This seems to have worked:

initscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.adarshr:gradle-test-logger-plugin:+'
    }
}

allprojects {
    apply plugin: com.adarshr.gradle.testlogger.TestLoggerPlugin
}

https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerPlugin.groovy

@patkujawa-wf patkujawa-wf changed the title Can it work as a Gradle init script? Can it work as a Gradle init script [Yes!] ? Jan 18, 2022
@patkujawa-wf patkujawa-wf reopened this Jan 18, 2022
@patkujawa-wf
Copy link
Author

patkujawa-wf commented Jan 18, 2022

Whoops, I guess the work isn't done. Now I get this exception over and over when I run my tests:

Failed to notify test listener.
org.gradle.internal.event.ListenerNotificationException: Failed to notify test listener.
...
Caused by: java.lang.AbstractMethodError: groovy/lang/GroovyObject.getProperty(Ljava/lang/String;)Ljava/lang/Object;
        at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
        at groovy.lang.Closure.getPropertyTryThese(Closure.java:313)
        at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:307)
        at groovy.lang.Closure.getProperty(Closure.java:296)
        at com.adarshr.gradle.testlogger.logger.SequentialTestLogger$_afterTest_closure2.doCall(SequentialTestLogger.groovy:39)
        at com.adarshr.gradle.testlogger.logger.SequentialTestLogger$_afterTest_closure2.call(SequentialTestLogger.groovy)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2330)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2315)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2356)
        at com.adarshr.gradle.testlogger.logger.SequentialTestLogger.afterTest(SequentialTestLogger.groovy:36)
        at com.adarshr.gradle.testlogger.logger.TestLoggerAdapter.afterTest(TestLoggerAdapter.groovy:81)
        at com.adarshr.gradle.testlogger.logger.TestLoggerWrapper.afterTest(TestLoggerWrapper.groovy:25)
        at jdk.internal.reflect.GeneratedMethodAccessor368.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:43)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:245)
        at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:157)
        at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:61)
        ... 41 more

Perhaps something to do with being written in groovy? I can test with the normal way of using this plugin and see if that also fails similarly.

@patkujawa-wf
Copy link
Author

I get the same exception when using the plugin in my project's build.gradle, so perhaps just something with my setup?

@disrupted
Copy link

@patkujawa-wf same here

@radarsh
Copy link
Owner

radarsh commented Mar 7, 2022

The exception you are seeing is mostly as a result of #241 (comment). There is nothing that can be done about that if you are using Gradle < 7 and plugin version > 3.1.0 I'm afraid.

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

No branches or pull requests

3 participants