How to use maven-publish to publish dependencies and transient dependencies


My team has a private maven repository that can’t be connected to the internet (its nexus if that matters). Before, to add artifacts to the repository, a team member would go and manually read all the maven POMs to find all the artifacts, and then upload them one-by-one through the web GUI. This is how all the dependencies for the projects were managed.

I thought this was ludicrious so I decided to try and automate this process. After reading around that there really isn’t a turn-key way to make a private maven mirror like can be done with apt, yum, npm, and pip, I thought I would try to do it with Gradle.

To start with, I thought I would try to grab the robolectric library and all of its dependencies in a gradle project on my thumbdrive, then move over to the maven repository and publish all the artifacts into the maven repository. I only got to the point of being able to dump the jars from the dependencies into a folder as can be seen in the build.gradle script I have attached.

Where I am running into problems is with the MavenPublication part, when I try to run $gradle generatePomFileForMavenJavaPublication I don’t get any of the dependencies for robolectric listed in my POM

I was reading through this issue on github which led me to this repository which I think does what I want, but is broken as of Gradle 7.

I don’t know if I am just making this unreasonably hard because I am new to Gradle, or if it is actually this hard to maintain a maven repository without internet connectivity, but I would really appreciate some help.


 * This file was generated by the Gradle 'init' task.
 * This is a general purpose Gradle build.
 * Learn more about Gradle by exploring our samples at
plugins {
    id 'distribution' //probably not needed anymore
    id 'application' //probably not needed anymore
    id 'maven-publish'
    id 'java-library' //probably not needed anymore

repositories {
    maven {
        url ''


dependencies {
    implementation 'org.robolectric:robolectric:4.5.1'

//nasty hack from
configurations {
    customConfig.extendsFrom implementation

//dumps the jar files for all the dependencies into the folder specified.
task copyLibs(type: Copy) {
    from configurations.customConfig
    into "$project.rootDir/reports/libs/"

//complement to copy libs
task cleanLibs(type: Delete){
    delete "$project.rootDir/reports"

publishing {
    publications {
        mavenJava(MavenPublication) {

    repositories {
        maven {
            name = 'testrepo'
            url = layout.buildDirectory.dir("repo")