Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created April 10, 2026 03:32
Show Gist options
  • Select an option

  • Save xuwei-k/00cad0a6ea1688563ed3e48272f5b43e to your computer and use it in GitHub Desktop.

Select an option

Save xuwei-k/00cad0a6ea1688563ed3e48272f5b43e to your computer and use it in GitHub Desktop.
@transient
val validatePom = taskKey[Unit]("")
def checkPom(pom: scala.xml.Node): List[String] = {
List(
"modelVersion",
"groupId",
"artifactId",
"version",
"packaging",
"name",
"description",
"url",
"licenses",
"developers"
).flatMap { tag =>
if ((pom \ tag).isEmpty) List("<" + tag + ">") else Nil
} ::: List(("scm", "url"), ("scm", "connection")).flatMap { case (tag1, tag2) =>
if ((pom \ tag1 \ tag2).isEmpty) List("<" + tag1 + "><" + tag2 + ">") else Nil
}
}
validatePom := {
val s = streams.value
if ((publish / skip).value) {
s.log.info(s"[name = ${name.value}][base = ${baseDirectory.value}] skip validatePom task")
None
} else {
makePom.?.value.map { ff =>
val f = fileConverter.value.toPath(ff).toFile
val errors = checkPom(scala.xml.XML.loadFile(f))
errors.foreach { e =>
s.log.error("missing tag " + e)
}
if (errors.isEmpty) {
s.log.info(s"[name = ${name.value}][base = ${baseDirectory.value}] success validatePom")
}
errors.isEmpty
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment