Skip to content

Instantly share code, notes, and snippets.

@lefou
Created March 12, 2018 13:15
Show Gist options
  • Save lefou/f61b2aee1ca59d6c0c776c1e51dd6327 to your computer and use it in GitHub Desktop.
Save lefou/f61b2aee1ca59d6c0c776c1e51dd6327 to your computer and use it in GitHub Desktop.
Mave Polyglot Scala file meant to be included in projects
// You should include this file from your pom.scala
// In your pom.scala (or somewhere else) you must define
// - a Deps object with the required dependencies
// - a Plugins object with the required plugin dependencies
import org.sonatype.maven.polyglot.scala.model._
import scala.collection.immutable._
object ReleaseProfile {
val mvnDeploySettingsFile = "mvn-deploy-settings.xml"
val mvnDeploySettings =
"""|<settings>
| <servers>
| <server>
| <id>ossrh</id>
| <!-- Enter your credentials here -->
| <username>your-username</username>
| <password>your-password</password>
| </server>
| </servers>
|</settings>
|""".stripMargin
def echoMvnDeploySettings: Config = new Config(
mvnDeploySettings.split("[\n]").toList.map { line =>
"echo" -> Some(Config(
`@file` = "${project.basedir}/" + mvnDeploySettingsFile,
`@append` = "true",
`@message` = line + "${line.separator}"
))
}
)
def apply(skipDeploy: Boolean = false): Profile = Profile(
id = "release",
build = BuildBase(
plugins = Seq(
Plugin(
Plugins.nexusStaging,
executions = Seq(
Execution(
id = "deploy-to-ossrh",
goals = Seq("deploy"),
configuration = Config(
skipNexusStagingDeployMojo = skipDeploy,
serverId = "ossrh",
nexusUrl = "https://oss.sonatype.org",
autoReleaseAfterClose = "true"
)
)
)
),
Plugin(
Plugins.antrun,
dependencies = Seq(
Dependency(Deps.antContrib, exclusions = Seq("*" % "*"))
),
executions = Seq(
Execution(
id = "prepare-nexus-staging",
phase = "initialize",
goals = Seq("run"),
configuration = Config(
target = Config(
taskdef = Config(
`@resource` = "net/sf/antcontrib/antlib.xml",
`@classpathref` = "maven.plugin.classpath"
),
`if` = Config(
available = Config(
`@file` = "${project.basedir}/" + mvnDeploySettingsFile
),
`else` = new Config(
echoMvnDeploySettings.elements ++ Config(
fail = Config(
`@unless` = "deploy-settings",
`@message` = "Created the file '" + mvnDeploySettingsFile + "'." +
"${line.separator}For deployment edit and add your credentials and then run:" +
"${line.separator} 'mvn -s " + mvnDeploySettingsFile + " -Prelease clean deploy'"
)).elements
)
)
)
)
),
// must be defined after the deploy task, to execeted after it
Execution(
id = "post-clean-info",
phase = "deploy",
goals = Seq("run"),
configuration = Config(
target = Config(
echo = Config(
`@message` = "Don't forget to clean/delete '" + mvnDeploySettingsFile + "'"
)
)
)
)
)
),
Plugin(
Plugins.source,
executions = Seq(
Execution(
id = "attach-sources",
goals = Seq("jar")
)
)
),
Plugin(
Plugins.javadoc,
executions = Seq(
Execution(
id = "attach-javadocs",
goals = Seq("jar")
)
)
),
Plugin(
Plugins.gpg,
executions = Seq(
Execution(
id = "sign-artifacts",
phase = "verify",
goals = Seq("sign")
)
)
)
)
)
)
}
@lefou
Copy link
Author

lefou commented Mar 12, 2018

Dependencies currently:

object Deps {
  val antContrib = "ant-contrib" % "ant-contrib" % "1.0b3"
}

object Plugins {
  val antrun = "org.apache.maven.plugins" % "maven-antrun-plugin" % "1.8"
  val asciidoctor = "org.asciidoctor" % "asciidoctor-maven-plugin" % "1.5.6"
  val clean = "org.apache.maven.plugins" % "maven-clean-plugin" % "3.0.0"
  val deploy = "org.apache.maven.plugins" % "maven-deploy-plugin" % "2.8.2"
  val gpg = "org.apache.maven.plugins" % "maven-gpg-plugin" % "1.6"
  val jar = "org.apache.maven.plugins" % "maven-jar-plugin" % "2.5"
  val javadoc = "org.apache.maven.plugins" % "maven-javadoc-plugin" % "3.0.0"
  val jxr = "org.apache.maven.plugins" % "maven-jxr-plugin" % "2.5"
  val nexusStaging = "org.sonatype.plugins" % "nexus-staging-maven-plugin" % "1.6.7"
  val plugin = "org.apache.maven.plugins" % "maven-plugin-plugin" % "3.5.1"
  val polyglotTranslate = "io.takari.polyglot" % "polyglot-translate-plugin" % "0.3.0"
  val projectInfoReports = "org.apache.maven.plugins" % "maven-project-info-reports-plugin" % "2.9"
  val site = "org.apache.maven.plugins" % "maven-site-plugin" % "3.7"
  val source = "org.apache.maven.plugins" % "maven-source-plugin" % "3.0.1"
  val surefire = "org.apache.maven.plugins" % "maven-surefire-plugin" % "2.20.1"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment