diff --git a/main/init/buildgen/src/mill/main/buildgen/BuildGenUtil.scala b/main/init/buildgen/src/mill/main/buildgen/BuildGenUtil.scala index 716d654a73c..8d9eb6caf4f 100644 --- a/main/init/buildgen/src/mill/main/buildgen/BuildGenUtil.scala +++ b/main/init/buildgen/src/mill/main/buildgen/BuildGenUtil.scala @@ -70,7 +70,7 @@ object BuildGenUtil { | |${renderCompileModuleDeps(scopedDeps.testCompileModuleDeps)} | - |${renderResources(Nil)} + |${renderResources(testResources)} |}""".stripMargin } @@ -104,6 +104,10 @@ object BuildGenUtil { | |${renderPublishProperties(Nil)} | + |${renderResources(resources)} + | + |${renderPublishProperties(publishProperties)} + | |$testModuleTypedef""".stripMargin } diff --git a/main/init/buildgen/src/mill/main/buildgen/ir.scala b/main/init/buildgen/src/mill/main/buildgen/ir.scala index e40c57edc64..62713c868f4 100644 --- a/main/init/buildgen/src/mill/main/buildgen/ir.scala +++ b/main/init/buildgen/src/mill/main/buildgen/ir.scala @@ -67,7 +67,10 @@ case class IrBuild( pomSettings: IrPom, publishVersion: String, packaging: String, - pomParentArtifact: String + pomParentArtifact: String, + resources: Seq[os.SubPath], + testResources: Seq[os.SubPath], + publishProperties: Seq[(String, String)] ) case class IrScopedDeps( diff --git a/main/init/gradle/src/mill/main/gradle/BuildGen.scala b/main/init/gradle/src/mill/main/gradle/BuildGen.scala index 2c1a9194664..60f4ff65371 100644 --- a/main/init/gradle/src/mill/main/gradle/BuildGen.scala +++ b/main/init/gradle/src/mill/main/gradle/BuildGen.scala @@ -181,31 +181,28 @@ object BuildGen { val scopedDeps = extractScopedDeps(project, packages, cfg) - val inner = { - val javacOptions = { + val inner = IrBuild( + scopedDeps, + cfg.shared.testModule, + hasTest, + dirs, + repos = getRepositories(project).diff(baseRepos), + javacOptions = { val options = getJavacOptions(project).diff(baseJavacOptions) if (options == baseJavacOptions) Seq.empty else options - } - val repos = getRepositories(project).diff(baseRepos) - val pomSettings = if (baseNoPom) extractPomSettings(project) else null - val publishVersion = { + }, + project.name(), + pomSettings = if (baseNoPom) extractPomSettings(project) else null, + publishVersion = { val version = getPublishVersion(project) if (version == basePublishVersion) null else version - } - IrBuild( - scopedDeps, - cfg.shared.testModule, - hasTest, - dirs, - repos, - javacOptions, - project.name(), - pomSettings, - publishVersion, - packaging = null, - pomParentArtifact = null - ) - } + }, + packaging = null, + pomParentArtifact = null, + resources = Nil, + testResources = Nil, + publishProperties = Nil + ) build.copy(value = BuildObject( diff --git a/main/init/maven/src/mill/main/maven/BuildGen.scala b/main/init/maven/src/mill/main/maven/BuildGen.scala index 9f7139789ea..e73f0433736 100644 --- a/main/init/maven/src/mill/main/maven/BuildGen.scala +++ b/main/init/maven/src/mill/main/maven/BuildGen.scala @@ -118,47 +118,35 @@ object BuildGen { val supertypes = Seq("RootModule") ++ - (cfg.shared.baseModule match { - case None => moduleSupertypes - case Some(v) => Seq(v) - }) + cfg.shared.baseModule.fold(moduleSupertypes)(Seq(_)) val scopedDeps = extractScopedDeps(model, packages, cfg) - val inner = { - val options = Plugins.MavenCompilerPlugin.javacOptions(model) - val javacOptions = if (options == baseJavacOptions) Seq.empty else options - - val pomSettings = if (baseNoPom) extractPomSettings(model) else null - val resources = model.getBuild.getResources.iterator().asScala - .map(_.getDirectory) - .map(os.Path(_).subRelativeTo(millSourcePath)) - .filterNot(_ == mavenMainResourceDir) - val version = model.getVersion - val publishVersion = if (version == basePublishVersion) null else version - - val publishProperties = getPublishProperties(model, cfg).diff(basePublishProperties) - val pomParentArtifact = mkPomParent(model.getParent) - - val testResources = model.getBuild.getTestResources.iterator().asScala - .map(_.getDirectory) - .map(os.Path(_).subRelativeTo(millSourcePath)) - .filterNot(_ == mavenTestResourceDir) - - IrBuild( - scopedDeps, - cfg.shared.testModule, - hasTest, - dirs, - repos = Nil, - javacOptions, - artifactId, - pomSettings, - publishVersion, - packaging, - pomParentArtifact - ) - } + val options = Plugins.MavenCompilerPlugin.javacOptions(model) + + def processResources(input: java.util.List[org.apache.maven.model.Resource]) = input + .asScala + .map(_.getDirectory) + .map(os.Path(_).subRelativeTo(millSourcePath)) + .filterNot(_ == mavenTestResourceDir) + .toSeq + + val inner = IrBuild( + scopedDeps, + cfg.shared.testModule, + hasTest, + dirs, + repos = Nil, + javacOptions = if (options == baseJavacOptions) Seq.empty else options, + artifactId, + pomSettings = if (baseNoPom) extractPomSettings(model) else null, + publishVersion = if (model.getVersion == basePublishVersion) null else model.getVersion, + packaging, + pomParentArtifact = mkPomParent(model.getParent), + resources = processResources(model.getBuild.getResources), + testResources = processResources(model.getBuild.getTestResources), + publishProperties = getPublishProperties(model, cfg).diff(basePublishProperties) + ) build.copy(value = BuildObject(