Skip to content

Commit

Permalink
fix: skip publish on synthetic aggregate root
Browse files Browse the repository at this point in the history
**Problem**
There's been previous attempt like 1878 to skip publishing of the root,
but it seems like the behavior has regressed at some point in time.

**Solution**
This skips publishing on synthetic aggregate root project.
  • Loading branch information
eed3si9n committed Sep 22, 2024
1 parent 336b752 commit 6491e50
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
17 changes: 12 additions & 5 deletions main/src/main/scala/sbt/internal/BuildDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ package sbt
package internal

import java.io.File
import Keys.{ organization, thisProject, autoGeneratedProject }
import Keys.{ organization, thisProject, autoGeneratedProject, publish, publishLocal, skip }
import Def.Setting
// import sbt.ProjectExtra.apply
import sbt.io.Hash
import sbt.internal.util.{ Attributed, StringAttributeMap }
import sbt.internal.inc.{ FileAnalysisStore, ReflectUtilities }
import sbt.SlashSyntax0.*
import xsbti.{ FileConverter, VirtualFileRef }
import xsbti.compile.CompileAnalysis

Expand All @@ -42,7 +43,7 @@ private[sbt] object BuildDef:
}

def defaultAggregated(id: String, aggregate: Seq[ProjectRef]): BuildDef = new BuildDef {
override def projectDefinitions(base: File) =
override def projectDefinitions(base: File): Seq[Project] =
defaultAggregatedProject(id, base, aggregate) :: Nil
}

Expand All @@ -55,12 +56,18 @@ private[sbt] object BuildDef:
def defaultAggregatedProject(id: String, base: File, agg: Seq[ProjectRef]): Project =
defaultProject(id, base).aggregate(agg: _*)

private[sbt] def generatedRootWithoutIvyPlugin(
private[sbt] def generatedRootSkipPublish(
id: String,
base: File,
agg: Seq[ProjectRef]
): Project =
Project.mkGeneratedRoot(id, base, agg).settings(defaultProjectSettings)
Project
.mkGeneratedRoot(id, base, agg)
.settings(
defaultProjectSettings,
publish / skip := true,
publishLocal / skip := true,
)

private[sbt] def defaultProjectSettings: Seq[Setting[_]] = Seq(
// TODO - Can we move this somewhere else? ordering of settings is causing this to get borked.
Expand All @@ -72,7 +79,7 @@ private[sbt] object BuildDef:
case _ => "default"
}
},
autoGeneratedProject := true
autoGeneratedProject := true,
)

def analyzed(
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/scala/sbt/internal/Load.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ private[sbt] object Load {
val refs = existingIds.map(id => ProjectRef(buildUri, id))
if (discovered.isEmpty || java.lang.Boolean.getBoolean("sbt.root.ivyplugin"))
BuildDef.defaultAggregatedProject(defaultID, buildBase, refs)
else BuildDef.generatedRootWithoutIvyPlugin(defaultID, buildBase, refs)
else BuildDef.generatedRootSkipPublish(defaultID, buildBase, refs)
}
(root, false, Nil, otherProjects)
val (finalRoot, projectLevelExtra) =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ThisBuild / organization := "com.example"
ThisBuild / ivyPaths := IvyPaths((ThisBuild / baseDirectory).value.toString, Some(((ThisBuild / baseDirectory).value / "ivy" / "cache").toString))

name := "root"

lazy val core = project
.settings(
name := "core",
// organization := "com.example",
ivyPaths := IvyPaths((ThisBuild / baseDirectory).value.toString, Some(((ThisBuild / baseDirectory).value / "ivy" / "cache").toString))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> publishLocal

$ absent ivy/cache/local/com.example/root_3/0.1.0-SNAPSHOT/poms/root_3.pom

0 comments on commit 6491e50

Please sign in to comment.