mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Add build logic to upload dependency JARs
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=225539482
This commit is contained in:
parent
b27a49c1b4
commit
296acf80bb
4 changed files with 139 additions and 0 deletions
|
@ -6,10 +6,13 @@ buildscript {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
|
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
|
||||||
|
classpath 'org.sonatype.aether:aether-api:1.13.1'
|
||||||
|
classpath 'org.sonatype.aether:aether-impl:1.13.1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
id 'nebula.dependency-lock' version '7.1.0'
|
||||||
id 'nebula.lint' version '10.3.5'
|
id 'nebula.lint' version '10.3.5'
|
||||||
// Config helper for annotation processors such as AutoValue and Dagger.
|
// Config helper for annotation processors such as AutoValue and Dagger.
|
||||||
// Ensures that source code is generated at an appropriate location.
|
// Ensures that source code is generated at an appropriate location.
|
||||||
|
@ -88,6 +91,8 @@ subprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven-publish'
|
||||||
|
apply plugin: 'nebula.dependency-lock'
|
||||||
apply plugin: 'nebula.lint'
|
apply plugin: 'nebula.lint'
|
||||||
apply plugin: 'net.ltgt.apt'
|
apply plugin: 'net.ltgt.apt'
|
||||||
|
|
||||||
|
@ -105,6 +110,100 @@ subprojects {
|
||||||
// TODO(weiminyu): enable more dependency checks
|
// TODO(weiminyu): enable more dependency checks
|
||||||
]
|
]
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = project.findProperty('gcsRepo')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.getDistinctResolvedArtifacts = {
|
||||||
|
def distinctResolvedArtifacts = [:]
|
||||||
|
|
||||||
|
configurations.each {
|
||||||
|
if (!it.isCanBeResolved()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
it.resolvedConfiguration.resolvedArtifacts.each { resolvedArtifact ->
|
||||||
|
if (resolvedArtifact.id.componentIdentifier.displayName in ['project :util', 'project :third_party']) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
distinctResolvedArtifacts[resolvedArtifact.id.toString()] = resolvedArtifact
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return distinctResolvedArtifacts
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.generateDependencyPublications = {
|
||||||
|
def distinctResolvedArtifacts = project.ext.getDistinctResolvedArtifacts()
|
||||||
|
|
||||||
|
distinctResolvedArtifacts.values().eachWithIndex { resolvedArtifact, n ->
|
||||||
|
project.publishing {
|
||||||
|
publications {
|
||||||
|
"maven${n}"(MavenPublication) {
|
||||||
|
artifact(resolvedArtifact.file) {
|
||||||
|
groupId = resolvedArtifact.moduleVersion.id.group
|
||||||
|
artifactId = resolvedArtifact.moduleVersion.id.name
|
||||||
|
version = resolvedArtifact.moduleVersion.id.version
|
||||||
|
classifier = resolvedArtifact.classifier
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.urlExists = { url ->
|
||||||
|
def connection = (HttpURLConnection) url.openConnection()
|
||||||
|
connection.setRequestMethod("HEAD")
|
||||||
|
connection.connect()
|
||||||
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.writeMetadata = { resolvedArtifact, url, gitRepositoryPath ->
|
||||||
|
def groupId = resolvedArtifact.moduleVersion.id.group
|
||||||
|
def artifactId = resolvedArtifact.moduleVersion.id.name
|
||||||
|
def version = resolvedArtifact.moduleVersion.id.version
|
||||||
|
def relativeFileName =
|
||||||
|
[groupId, artifactId, 'README.domainregistry'].join('/')
|
||||||
|
def metadataFile = new File(gitRepositoryPath, relativeFileName)
|
||||||
|
metadataFile.parentFile.mkdirs()
|
||||||
|
def writer = metadataFile.newWriter()
|
||||||
|
writer << "Name: ${artifactId}\n"
|
||||||
|
writer << "Url: ${url}\n"
|
||||||
|
writer << "Version: ${version}\n"
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This task generates a metadata file for each resolved dependency artifact.
|
||||||
|
// The file contains the name, url and version for the artifact.
|
||||||
|
task generateDependencyMetadata {
|
||||||
|
doLast {
|
||||||
|
def distinctResolvedArtifacts = project.ext.getDistinctResolvedArtifacts()
|
||||||
|
def defaultLayout = new org.sonatype.aether.util.layout.MavenDefaultLayout()
|
||||||
|
|
||||||
|
distinctResolvedArtifacts.values().each { resolvedArtifact ->
|
||||||
|
def artifact = new org.sonatype.aether.util.artifact.DefaultArtifact(
|
||||||
|
resolvedArtifact.id.componentIdentifier.toString())
|
||||||
|
for (repository in project.repositories) {
|
||||||
|
def mavenRepository = (MavenArtifactRepository) repository
|
||||||
|
def repositoryUri = URI.create(mavenRepository.url.toString())
|
||||||
|
def artifactUri = repositoryUri.resolve(defaultLayout.getPath(artifact))
|
||||||
|
if (project.ext.urlExists(artifactUri.toURL())) {
|
||||||
|
project.ext.writeMetadata(resolvedArtifact, artifactUri.toURL(), project.findProperty('privateRepository') + "/${project.name}")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (project.name == 'third_party') return
|
if (project.name == 'third_party') return
|
||||||
|
|
||||||
// Path to code generated with annotation processors. Note that this path is
|
// Path to code generated with annotation processors. Note that this path is
|
||||||
|
|
|
@ -466,3 +466,4 @@ task nomulus(type: Jar) {
|
||||||
dependsOn project(':third_party').jar
|
dependsOn project(':third_party').jar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.generateDependencyPublications()
|
||||||
|
|
|
@ -99,3 +99,5 @@ docker {
|
||||||
ports = [30000, 30001, 30002, 30011, 30012]
|
ports = [30000, 30001, 30002, 30011, 30012]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ext.generateDependencyPublications()
|
||||||
|
|
37
gradle/update_dependency.sh
Executable file
37
gradle/update_dependency.sh
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
#
|
||||||
|
# This script runs a workflow to generate dependency lock file, run a build against
|
||||||
|
# the generated lock file, save the lock file and upload dependency JARs to a private
|
||||||
|
# Maven repository if the build succeeds.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ALL_SUBPROJECTS="core proxy util"
|
||||||
|
SUBPROJECTS=
|
||||||
|
|
||||||
|
if [[ -z "$@" ]]; then
|
||||||
|
SUBPROJECTS="${ALL_SUBPROJECTS}"
|
||||||
|
else
|
||||||
|
SUBPROJECTS="$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for PROJECT in ${SUBPROJECTS}; do
|
||||||
|
./gradlew ":${PROJECT}:generateLock"
|
||||||
|
./gradlew -PdependencyLock.useGeneratedLock=true ":${PROJECT}:build"
|
||||||
|
./gradlew ":${PROJECT}:saveLock"
|
||||||
|
./gradlew ":${PROJECT}:publish"
|
||||||
|
done
|
Loading…
Add table
Add a link
Reference in a new issue