Я разрабатываю собственный плагин Gradle на основе отражений : https://github.com/RoRoche/plantuml-gradle-plugin/tree/feature/using_reflections
Мне приходится иметь дело с некоторыми особенностями Gradle, такими как:
final URL[] urls = project.sourceSets.main.output.classesDirs.files.collect {
if (it != null) {
it.toURI().toURL()
}
}.findAll {
it != null
} as URL[]
getLogger().debug(
"URLs to scan: " + urls
)
return new URLClassLoader(urls)
И затем я создаю отражение, например:
/**
* Utility class to find [Classes] in a given package.
*
* @property packageName The name of the package to scan.
* @property reflections Utility to find classes in package.
*/
class ClsInPackage(
private val packageName: String,
private val reflections: Reflections
) : Classes {
/**
* Secondary constructor with reflections configuration.
*
* @param packageName The name of the package to scan.
* @param configuration The [Configuration] to use.
*/
constructor(
packageName: String,
configuration: Configuration
) : this(
packageName = packageName,
reflections = Reflections(configuration)
)
/**
* Secondary constructor.
*
* @param packageName The name of the package to scan.
* @param classLoader The [ClassLoader] to use.
*/
constructor(
packageName: String,
classLoader: ClassLoader
) : this(
packageName = packageName,
configuration = ConfigurationBuilder(
).setUrls(
ClasspathHelper.forClassLoader(classLoader)
).setScanners(
SubTypesScanner(false),
TypeAnnotationsScanner()
).addClassLoader(
classLoader
)
)
/**
* Secondary constructor.
*
* @param packageName The name of the package to scan.
* @param urls The [URL] array to use.
*/
constructor(
packageName: String,
urls: Array<URL>
) : this(
packageName = packageName,
classLoader = URLClassLoader(urls)
)
/**
* @return Classes to be used for diagram generation.
*/
override fun list(): List<Class<out Any>> {
val list = reflections.getSubTypesOf(
Any::class.java
).asIterable().toList()
if (list.isNullOrEmpty()) {
throw InvalidPackageException(packageName)
}
return list
}
}
После публикации моего плагина в mavenLocal и его использования в другом проекте я получаю следующую ошибку:
org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/Users/Romain/GitHub/eo-plantuml-builder/build/classes/java/main]
either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
Есть идеи, как это исправить?