diff --git a/src/main/kotlin/nmcp/NmcpAggregation.kt b/src/main/kotlin/nmcp/NmcpAggregation.kt index 5db5ead..9e6d4f3 100644 --- a/src/main/kotlin/nmcp/NmcpAggregation.kt +++ b/src/main/kotlin/nmcp/NmcpAggregation.kt @@ -3,16 +3,19 @@ package nmcp import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.provider.Property +import javax.inject.Inject -class NmcpAggregation( + +abstract class NmcpAggregation @Inject constructor( private val configuration: Configuration, private val project: Project, - val username: Property, - val password: Property, - val publicationType: Property, - val publicationName: Property, - val endpoint: Property, ) { + abstract val username: Property + abstract val password: Property + abstract val publicationType: Property + abstract val publicationName: Property + abstract val endpoint: Property + fun project(path: String) { project.dependencies.add(configuration.name, project.dependencies.project(mapOf("path" to path))) } diff --git a/src/main/kotlin/nmcp/NmcpExtension.kt b/src/main/kotlin/nmcp/NmcpExtension.kt index 55b8a25..420c4ce 100644 --- a/src/main/kotlin/nmcp/NmcpExtension.kt +++ b/src/main/kotlin/nmcp/NmcpExtension.kt @@ -6,7 +6,7 @@ import org.gradle.api.publish.PublishingExtension import org.gradle.api.tasks.bundling.Zip import org.gradle.configurationcache.extensions.capitalized -class NmcpExtension(private val project: Project) { +open class NmcpExtension(private val project: Project) { private var mavenPublishFound = false private val publishAllPublicationsToCentralPortal = project.tasks.register("publishAllPublicationsToCentralPortal") @@ -84,13 +84,7 @@ class NmcpExtension(private val project: Project) { } private fun publishInternal(publicationName: String?, action: Action) { - val spec = NmcpSpec( - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - ) + val spec = project.objects.newInstance(NmcpSpec::class.java) action.execute(spec) project.plugins.withId("maven-publish") { @@ -139,15 +133,7 @@ class NmcpExtension(private val project: Project) { it.configureAttributes(project) } - val aggregation = NmcpAggregation( - configuration, - project, - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - ) + val aggregation = project.objects.newInstance(NmcpAggregation::class.java, configuration, project) action.execute(aggregation) @@ -184,13 +170,7 @@ class NmcpExtension(private val project: Project) { "publishAllProjectsProbablyBreakingProjectIsolation() must be called from root project" } - val spec = NmcpSpec( - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - project.objects.property(String::class.java), - ) + val spec = project.objects.newInstance(NmcpSpec::class.java) action.execute(spec) publishAggregation { aggregation -> diff --git a/src/main/kotlin/nmcp/NmcpPlugin.kt b/src/main/kotlin/nmcp/NmcpPlugin.kt index 8725880..8666bbd 100644 --- a/src/main/kotlin/nmcp/NmcpPlugin.kt +++ b/src/main/kotlin/nmcp/NmcpPlugin.kt @@ -28,6 +28,6 @@ class NmcpPlugin: Plugin { it.configureAttributes(target) } - target.extensions.add("nmcp", NmcpExtension(target)) + target.extensions.create("nmcp", NmcpExtension::class.java, target) } } \ No newline at end of file diff --git a/src/main/kotlin/nmcp/NmcpSpec.kt b/src/main/kotlin/nmcp/NmcpSpec.kt index 3e1f41e..6b56a5e 100644 --- a/src/main/kotlin/nmcp/NmcpSpec.kt +++ b/src/main/kotlin/nmcp/NmcpSpec.kt @@ -2,10 +2,10 @@ package nmcp import org.gradle.api.provider.Property -class NmcpSpec( - val username: Property, - val password: Property, - val publicationType: Property, - val publicationName: Property, - val endpoint: Property, -) \ No newline at end of file +abstract class NmcpSpec { + abstract val username: Property + abstract val password: Property + abstract val publicationType: Property + abstract val publicationName: Property + abstract val endpoint: Property +} \ No newline at end of file