Circular dependency when publishing to jitpack

19 views Asked by At

What happened?

My project structure looks like this:

|--build-logic
|--core
  |--sub-core1
  |--sub-core2
|--data
  |--sub-data1
  |--sub-data2

I'm trying to publish both sub-core1 and sub-data1 only.

sub-core1 contains all the utility methods that sub-data1 have so it depends on it:

dependencies {
   api(projects.core.subCore1)
}

Every library I need to publish has the same code:

afterEvaluate {
    publishing {
        publications {
            create<MavenPublication>("release") {
                from(components["release"])

                groupId = "com.github.myUsername"
                artifactId = "name_of_this_module"
            }
        }

        repositories {
            mavenLocal()

            val token = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")

            if (token != null) {
                maven {
                    credentials {
                        username = "myUsername"
                        password = token
                    }
                    setUrl("https://maven.pkg.github.com/myUsername/RepositoryName")
                }
            }
        }
    }
}

Everytime I try to push it to github for publishing, it throws an error inside the build logs:

* Exception is:
org.gradle.api.CircularReferenceException: Circular dependency between the following tasks:
:core:sub-core1:insertRandomTask
\--- :core:sub-core1:insertRandomTask (*)

// Note that `insertRandomTask` is the same task.

And I was finally able to hunt down the error by running the command that jitpack uses when it needs to publish my library:

./gradlew clean -Pgroup=com.github.myUsername -Pversion=master-commit_number-1 -xtest -xlint assemble publishToMavenLocal

Turns out it was this argument that throws an error: -Pgroup=com.github.myUsername

What I did

  • I tried removing the -Pgroup argument and gradle worked just fine.
  • I tried adding --no-build-cache since I'm using gradle caching. I thought it would fix it but it didn't work.
  • I tried running the said tasks on a specific module (:data:sub-data1:clean -Pgroup=...), but it threw a new circular dependency exception but different module!!
  • Manually added the group = "com.github.myUsername" to allprojects extension.
  • Tried publishing the whole project (or all libraries). No luck :/

Question

Is there something wrong about my project structure that causes these circular dependency errors? This is my first time publishing a library.

0

There are 0 answers