Hey everyone, When using Groovy and applying the ...
# gradle
f
Hey everyone, When using Groovy and applying the
maven-publish
plugin and listing the tasks we have the task
publishAllPublicationsToMavenRepository
But when using the same
maven-publish
with Kotlin Gradle script, there's no task
publishAllPublicationsToMavenRepository
How do we fix this?
v
There should be no difference between Groovy and Kotlin DSL. Maybe you did not define any publication in the Kotlin version, or you did not define the publication repository called
maven
in the Kotlin version.
f
Previous setup in groovy was this
Screenshot_20230703-144244.png,Screenshot_20230703-144235.png,Screenshot_20230703-144229.png,Screenshot_20230703-144222.png,Screenshot_20230703-144215.png,Screenshot_20230703-144206.png
When translated into Kotlin
Screenshot_20230703-144409.png,Screenshot_20230703-144342.png,Screenshot_20230703-144336.png,Screenshot_20230703-144323.png
srcDirs is unable to be obtained since it's a function for Kotlin And also sourcesets main Kotlin doesn't exist, i tried making it
sourcesets["main"].allSources
And removed the kotlin srcDirs in order to compile because
kotlin.srcDirs
is a function invocation to set the srcDirs, there isn't any getter
Also registering the artifacts in Kotlin (last image that has the androidSourcesJar task by doing:
Copy code
artifacts {     
add("archives", androidSourcesJar) 
}
v
There are many bad-practices in that code, but the problem is exactly what I said. You did not define an repositories for publishing.
While doing the transition, you moved the publishing repository to
dependencyResolutionManagement { repositories { ... } }
which as the name suggests is for dependency resolution, not for publishing.
In the Groovy version, you had them in the
publishing { repositories { ... } }
where you have to define repositories for publishing.
So, no publishing repository => no publishing tasks
f
I've tried but the task we use is still not available, all other tasks are (publish, publishToMavenLocal, publishReleasePublicationToMavenLocal) But no:
publishAllPublicationsToMavenRepository
Since you mentioned bad practices, how do we make it better and also fix the issue?
v
I've tried but the task we use is still not available
Then you still did not define the publishing repository
I'm sorry, but I don't have time for an in-depth review, especially not of screenshots which always are a bad way to share code. But some of them from a very cursory look: - extra properties are almost always bad - afterEvaluate is practically always bad except for very special cases - manually manipulating the POM, especially as it then deviates from the Gradle Module Metadata - subprojects { ... } / allprojects { ... } are bad - project.plugins should not be used according to its JavaDoc - apply(...) for applying plugins is bad - tasks.creating instead of tasks.registering - ...
f
Thanks so much, I'll try and change the aforementioned things, if I can't succeed I'll share code snippets