diff --git a/gradle/build-mavenpublish.gradle b/gradle/build-mavenpublish.gradle new file mode 100644 index 0000000..678fb0e --- /dev/null +++ b/gradle/build-mavenpublish.gradle @@ -0,0 +1,53 @@ +/* + * Enables maven publish handling on build process + * + * Project: gradle + * Author: Marc Böhm + * License: MIT License (see LICENSE.md) + * + * Copyright (c) captica GmbH est. 2021 + */ + +// Load external plugins +buildscript { + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +project.ext { + mavenAccessToken = ( project.hasProperty('MAVEN_PUBLISH_ACCESS_TOKEN') ? MAVEN_ACCESS_TOKEN : null ) + mavenRepositoryUrl = ( project.hasProperty('MAVEN_PUBLISH_REPOSITORY_URL') ? MAVEN_PUBLISH_REPOSITORY_URL : null ) +} + +// Fail fast +if ( mavenAccessToken == null || mavenRepositoryUrl == null ) { + throw new GradleScriptException("Missing required properties: MAVEN_PUBLISH_ACCESS_TOKEN and MAVEN_PUBLISH_REPOSITORY_URL") +} + +// Apply plugins +apply plugin: 'maven-publish' + +// Configure maven publish +publishing { + publications { + bootJava(MavenPublication) { + artifact tasks.named("bootJar") + } + } + repositories { + maven { + url uri(mavenRepositoryUrl) + + credentials(HttpHeaderCredentials) { + name = "Authorization" + value = "token ${mavenAccessToken}" + } + + authentication { + header(HttpHeaderAuthentication) + } + } + } +} \ No newline at end of file