Using class from applied .gradle file in build.gradle

(Gleb) #1

I have following:
class MyClass {..}
apply from: "$rootDir/gradle/my.gradle" smth = new MyClass(..)

unable to resolve class MyClass

Any way to “import” MyClass in build.gradle to make it work?

(Stefan Oehme) #2

Classes from a script plugin cannot be referenced currently. If you want to write classes that all your build scripts can see, please use the buildSrc project.

(Gleb) #3

That’s sad. I want this my.gradle to be used in other projects and it is actually fetched into from remote repository, I gave $rootDir/gradle/my.gradle just as an example.
Was expecting to have some preemptive definition.

Is there a possibility of creating my own “real” plugin containing this class?

(Stefan Oehme) #4

Of course, just build a plugin and use that instead. That’s recommended over remote scripts anyway :slight_smile: