All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.name.remal.gradle_plugins.plugins.dependencies.ConfigurationExtension.kt Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package name.remal.gradle_plugins.plugins.dependencies

import name.remal.gradle_plugins.dsl.Extension
import name.remal.gradle_plugins.dsl.extensions.applyLoggingTransitiveDependenciesExcludes
import name.remal.gradle_plugins.dsl.extensions.newLoggingLoadingOrderFactory
import name.remal.reflection.ExtendedURLClassLoader
import name.remal.reflection.ExtendedURLClassLoader.LoadingOrder
import name.remal.reflection.ExtendedURLClassLoader.LoadingOrder.PARENT_FIRST
import name.remal.reflection.ExtendedURLClassLoader.LoadingOrder.THIS_FIRST
import name.remal.reflection.ExtendedURLClassLoader.LoadingOrder.THIS_ONLY
import org.gradle.api.artifacts.Configuration
import java.net.URLClassLoader

@Extension
class ConfigurationExtension(
    private val configuration: Configuration
) {

    fun excludeLogging() {
        configuration.applyLoggingTransitiveDependenciesExcludes()
    }


    private fun createClassLoader(loadingOrder: LoadingOrder): URLClassLoader {
        val loadingOrderFactory = newLoggingLoadingOrderFactory(loadingOrder)
        val urls = configuration.files.map { it.toURI().toURL() }
        return ExtendedURLClassLoader(loadingOrderFactory, urls, this.javaClass.classLoader)
    }

    fun createClassLoader() = createClassLoader(PARENT_FIRST)

    fun createThisOnlyClassLoader() = createClassLoader(THIS_ONLY)

    fun createThisFirstClassLoader() = createClassLoader(THIS_FIRST)

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy