SourceDirectorySetFactory use is relatively safe here, as it is injected by DI and passed to the DefaultGosuSourceSet constructor. More on that later.
Cast is used to coerce a SourceSetOutput instance to DefaultSourceSetOutput so that I may access the addClassesDir(Callable<File>) method. Normally this is done safely inside the org.gradle.api.plugins.internal.SourceSetUtil#configureOutputDirectoryForSourceSet method, but since SourceSetUtil is also internal I decided to make copies of the methods. But perhaps a better solution is to expose SourceSetUtil as public?
As mentioned above, I call the create(String, String) method on an injected reference to SourceDirectorySetFactory. I then set reasonable defaults on the created SourceDirectorySets.
This code is very similar to org.gradle.api.tasks.ScalaRuntime, which dynamically adds a dependency on artifact org.scala-lang:scala-compiler based on the version of existing dependency org.scala-lang:scala-library. Just like that code, GosuRuntime needs to perform late evaluation of the dependencies or it will fail if run too soon in the build.
--
If there are better ways to do any or all of the above without depending on internal APIs, I would welcome help/advice on how to isolate this plugin from core changes. It's a win-win!
As a follow-up to #39, there are a handful of additional places where I have no choice (AFAICT) but to use Gradle internal APIs.
Here are the remaining usages as of
v0.3.7
and the justification for them.org.gosulang.gradle.GosuBasePlugin
Internal APIs used:
org.gradle.api.internal.file.SourceDirectorySetFactory
org.gradle.api.internal.tasks.DefaultSourceSetOutput
org.gradle.internal.Cast
Justification:
SourceDirectorySetFactory
use is relatively safe here, as it is injected by DI and passed to theDefaultGosuSourceSet
constructor. More on that later.Cast
is used to coerce aSourceSetOutput
instance toDefaultSourceSetOutput
so that I may access theaddClassesDir(Callable<File>)
method. Normally this is done safely inside theorg.gradle.api.plugins.internal.SourceSetUtil#configureOutputDirectoryForSourceSet
method, but sinceSourceSetUtil
is also internal I decided to make copies of the methods. But perhaps a better solution is to exposeSourceSetUtil
as public?org.gosulang.gradle.tasks.DefaultGosuSourceSet
Internal APIs used:
org.gradle.api.internal.file.SourceDirectorySetFactory
Justification:
create(String, String)
method on an injected reference toSourceDirectorySetFactory
. I then set reasonable defaults on the createdSourceDirectorySet
s.org.gosulang.gradle.tasks.GosuRuntime
Internal APIs used:
org.gradle.api.internal.file.collections.LazilyInitializedFileCollection
org.gradle.api.internal.tasks.TaskDependencyResolveContext
Justification:
org.gradle.api.tasks.ScalaRuntime
, which dynamically adds a dependency on artifactorg.scala-lang:scala-compiler
based on the version of existing dependencyorg.scala-lang:scala-library
. Just like that code,GosuRuntime
needs to perform late evaluation of the dependencies or it will fail if run too soon in the build.--
If there are better ways to do any or all of the above without depending on internal APIs, I would welcome help/advice on how to isolate this plugin from core changes. It's a win-win!