Hello. I have a plugin that lives in `buildSrc` wh...
# general
r
Hello. I have a plugin that lives in
buildSrc
which provides a specialization of
Test
task types. I am trying to move it from
buildSrc
into a separate sub-project, consumed by
includeBuild
. The plugin project builds and creates its jar as expected, but the main project cannot create the tasks any more, reporting:
Copy code
Could not get unknown property 'RepeatTest' for project ':geode-assembly' of type org.gradle.api.Project.
c
When in buildSrc the plugin is always in the classpath, with includeBuild it doesn't, so, you need to apply the plugin to have it in the classpath. (You didn't provide a lot of info so I'm just guessing here)
r
Sorry about that. In
settings.gradle
, I have
Copy code
pluginManagement {
  includeBuild("buildSrc2")
}
and in the root
build.src
,
Copy code
plugins {
  id 'org.apache.geode.gradle.geode-repeat-test'
}
which triggers the plugin project being built (i see the library, with the test-task .class) In a sub-project, I try
Copy code
apply plugin: 'org.apache.geode.gradle.geode-repeat-test'

tasks.register('repeatTest', org.apache.geode.gradle.testing.repeat.RepeatTest) {}
and get
Could not get unknown property 'org' for project ':geode-assembly' of type org.gradle.api.Project
My understanding was that any class in the same package as the one implementing
Plugin<Project>
would be available on the build classpath. There isn’t any reason to add an extension to the Project, right?
c
If the class is public, and you apply the plugin it should be available, yes
r
Inspecting the compiled class file from the subproject, i see that it is
public class RepeatTest extends Test implements GroovyObject {}
Where
Test
is
org.gradle.api.tasks.testing.Test
v
Why do you use the legacy
apply
in the sub project?
But independent of that, try to import the class instead of using it fully-qualified. Sometimes that doesn't work properly
r
In the root project, I had been using
Copy code
plugins {
  id 'org.apache.geode.gradle.geode-repeat-test' apply false
}
because the root and some others do not have tests and ergo do not need the plugin, and then using
apply
to turn it on in the
java-library
projects. I’ve tried importing, and its not able to resolve 😕
g
You would likely need to apply plugin in projects where you use it via plugins block. I'm not sure if adding it in the root project with
apply false
would add it to subprojects' classpath. Usually it would be done in convention plugin which will also apply java-library plugin
v
It should. But nevertheless, you didn't say anything that is a reason to use the legacy
apply
r
Oh. There is a
test.gradle
that has test logic that is added to required projects. I can’t use
plugins{}
there because it is not a project
build.gradle
. I’ll pull it up, and see if that helps.
v
Ah, now we have it
☝️ 1
Yes, script plugins are very limited in their possibilities and also do not get the class loader parent like the actual project build script
If would basically never use script plugins, but always use precompiled script plugins for shared build logic
r
Yikes. You are saying to test this, I might have to migrate everything from buildscripts to better-formed plugins?
v
If you use precompiled script plugins, they look almost like normal build scripts
r
And this goes into
buildSrc
for starters, and can then be moved into an independent project if needed?
v
I never use
buildSrc
nowadays, but always an included build. But yes, you can also do it in
buildSrc
.
r
i’ll avoid buildSrc and try to move them into the cleverly-named
buildScripts