Skip to content

Selective Execution Invalidates resolvePublishDependency Task When Adding Modules To A Build #6871

Closed

Description

@maxstreese

When adding a new module to an existing Mill build that is independent of any other build modules, Mill invalidates the resolvePublishDependency Task. This can lead to many more tasks getting selectively resolved/run than you would like.

The below Bash script illustrates the issue and can be executed for reproduction:

curl -L https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/1.1.2/mill-dist-1.1.2-mill.sh -o mill

sudo chmod +x mill

cat <<'EOF' > build.mill
//| mill-version: 1.1.2
//| mill-jvm-version: temurin:25

package build

import mill.*
import mill.scalalib.*

object `package` extends Module:

  object foo extends ScalaModule:
    override def scalaVersion = "3.8.1"
EOF

./mill selective.prepare

cat <<'EOF' >> build.mill

  object bar extends ScalaModule:
    override def scalaVersion = "3.8.1"
EOF

./mill selective.resolveTree __.compile

The output of the final selective.resolveTree command yields:

{
  "def build_.package_$bar$#resolvePublishDependency()mill.api.Task": {
    "external mill.scalalib.ScalaModule": {
      "call mill.scalalib.ScalaModule.compile$(mill.scalalib.ScalaModule)mill.api.Task$Simple": {
        "def build_.package_$foo$#compile()mill.api.Task$Simple": {
          "foo.compile": {}
        }
      }
    }
  },
  "def build_.package_.<clinit>()void": {
    "call build_.package_.<clinit>()void": {
      "def build_.package_$#<init>()void": {
        "bar.compile": {}
      }
    }
  }
}

From my perspective as a user, this is unexpected. As someone who is in the process of setting up Mill for a large monorepo, this is also quite problematic because it means that when I onboard another application module to the build, my selective CI workflows would publish all existing apps/libs, which is exactly what I would like to prevent by using selective execution.

Activity

  1. maxstreese commented on Feb 24, 2026

    @maxstreese
    ContributorAuthor

    @lihaoyi any assessment here? Is this expected? Am I doing something obviously wrong? For my monorepo use case described above this is quite the obstacle unfortunately.

  2. lihaoyi commented on Feb 24, 2026

    @lihaoyi
    Member

    @maxstreese I think it's an expected limitation. Selective execution in the presence of code changes is generally best-effort and conservative, so although we do our best to try and make it as precise as possible, we can't guarantee there won't be false positives causing things to run more than they need to be. The assumption is that it is used for CI workflows where some amount of over-testing is benign.

    I can try to improve this particular scenario, but there will be definitely be other scenario causing unnecessary test selection in future, and we will never be able to fix all of them

  3. lihaoyi commented on Feb 24, 2026

    @lihaoyi
    Member

    This particular issue seems to be caused by our conservative treatment of virtual method calls, where we treat the as possibly dispatching to any known subclass. To be more precise would be an open research question of how we can improve the precision of our callgraph modelling without dramatically increasing the cost of computing the callgraph, so I wouldn't hold my breath on a fix

  4. maxstreese commented on Feb 24, 2026

    @maxstreese
    ContributorAuthor

    Ah ok, thanks for the detailed response! Curious to see if the fix you are attempting right now yield a result. In any case, feel free to close this issue then.

  5. added this to the 1.1.3 milestone on Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions