src / Main── main │ ├── java │ │ └── com │ │ └── example │ │ ├── logger │ │ └── util
buildscript { repositories { jcenter() } dependencies { classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1' } } allprojects { repositories { jcenter() } } // Artifactory apply plugin: 'com.jfrog.artifactory' // apply plugin: 'maven-publish' // , apply plugin: 'groovy' // apply from: 'components.gradle' dependencies { // Gradle Gradle API compile gradleApi() }
// def components = [ [name: 'logger', version:'1.0'], [name: 'util', version:'1.0'] ]
// . // compileUtil compileLogger, jar components.each { component -> task "compile${component.name.capitalize()}" (type: Jar) { version component.version classifier component.classifier baseName component.name from sourceSets.main.output // // . // include exclude, task.include "com/example/${component.name}/**" } }
// , class ComponentsJar extends Jar { } // task "compile${component.name.capitalize()}" (type: ComponentsJar) { // task compileComponents {} // compileComponents.dependsOn { tasks.withType(ComponentsJar) }
build / libs / Log── logger-1.0.jar Util── util-1.0.jar
implementation-class=com.example.MyPluginClass
// Gradle // , packagePrefix. // , // packagePrefix def plugins = [ [name:'android-signing', version:'1.0', packagePrefix:'signing'], [name:'android-library-publishing', version:'1.0', packagePrefix:'publishing'], [name:'android-base', version:'1.0', packagePrefix:'android'] ] // plugins.each { component -> task "compile${component.name.capitalize()}" (type: ComponentsJar) { // jar 'plugin' appendix 'plugin' version component.version classifier component.classifier baseName component.name from sourceSets.main.output def componentPackages = [] // , componentPackages.add("META-INF/gradle-plugins/${component.name}.properties") // , , componentPackages.add(component.packagePrefix ? "com/example/${component.packagePrefix}/**" : "com/example/${component.name}/**") include componentPackages } }
src / main / Resources── resources MET── META-INF Dle── gradle-plugins And── android-base.properties And── android-library-publishing.properties And── android-signing.properties
implementation-class=com.example.android.BaseAndroidConfiguration
src / main / Gro── groovy Com── com Example── example And── android │ └── BaseAndroidConfiguration.groovy Publishing── publishing │ └── LibraryPublishingPlugin.groovy Signing── signing Sign── SigningPlugin.groovy
build / libs / And── android-base-plugin-1.0.jar And── android-library-publishing-plugin-1.0.jar And── android-signing-plugin-1.0.jar Log── logger-1.0.jar Util── util-1.0.jar
// , class Artifact { String path, groupId, version, id, name } // Artifact, // compileComponents (. ) def artifacts = []; // Artifact, , // def activeArtifacts = []; // // , // artifacts publishing { publications { artifacts.each { art -> "$art.name"(MavenPublication) { groupId art.groupId version = art.version artifactId art.id artifact(art.path) } } } } // artifactory , activeArtifacts // . . artifactoryPublish { doFirst { activeArtifacts.each { artifact -> publications(artifact.name) } } } //.. // , artifactory { contextUrl = ArtifactoryUrl publish { repository { // , repoKey = 'libs-release-local' username = ArtifactoryUser password = ArtifactoryPassword } } }
// , class ComponentsJar extends Jar { } // , class Artifact { String path, groupId, version, id, name } // Artifact, def artifacts = []; // Artifact, , // def activeArtifacts = []; // def components = [ [name: 'logger', version:'1.0'], [name: 'util', version:'1.0'] ] // Gradle def plugins = [ [name:'android-signing', version:'1.0', packagePrefix:'signing'], [name:'android-library-publishing', version:'1.0', packagePrefix:'publishing'], [name:'android-base', version:'1.0', packagePrefix:'android'] ] // def baseTask = { task, component, packages -> task.version component.version task.classifier component.classifier task.baseName component.name task.from sourceSets.main.output def componentPackages = [] // , , componentPackages.add(component.packagePrefix ? "com/example/${component.packagePrefix}/**" : "com/example/${component.name}/**") if (packages != null) { componentPackages.addAll(packages) } task.include componentPackages // def art = new Artifact( name: component.name, groupId: "com.example", path: "$buildDir/libs/$task.archiveName", id: task.appendix == null ? component.name : "$component.name-$task.appendix", version: component.version ) // artifacts.add(art) // , task.doFirst { // activeArtifacts.add(art) } // pom.xml task.doLast { tasks."generatePomFileFor${art.name.capitalize()}Publication".execute() } } // components.each { component -> task "compile${component.name.capitalize()}" (type: ComponentsJar) { baseTask(it, component, component.package) } } // plugins.each { component -> task "compile${component.name.capitalize()}" (type: ComponentsJar) { // jar 'plugin' ( ) appendix 'plugin' // , def packages = ["META-INF/gradle-plugins/${component.name}.properties"] if (component.package != null) { packages.addAll(component.package) } baseTask(it, component, packages); } } // task compileComponents {} // compileComponents.dependsOn { tasks.withType(ComponentsJar) } jar { // jar doLast { new File(it.destinationDir, "${project.name}.jar").delete() } } // // , // artifacts publishing { publications { artifacts.each { art -> "$art.name"(MavenPublication) { groupId art.groupId version = art.version artifactId art.id artifact(art.path) } } } } // artifactory , artifactoryPublish { doFirst { activeArtifacts.each { artifact -> publications(artifact.name) } } } artifactory { contextUrl = ArtifactoryUrl publish { repository { // , repoKey = 'libs-release-local' username = ArtifactoryUser password = ArtifactoryPassword } } }
ArtifactoryUrl=http://localhost:8081 ArtifactoryUser=admin ArtifactoryPassword=password
dependencie { compile 'com.example:util:1.0' compile 'com.example:logger:1.0' }
allprojects { repositories { jcenter() maven { url "$ArtifactoryUrl/libs-release-local" credentials { username = ArtifactoryUser password = ArtifactoryPassword } } } }
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" publishNonDefault true defaultConfig { minSdkVersion 15 targetSdkVersion 21 } packagingOptions { exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE.txt' } testOptions { unitTests.returnDefaultValues = true } lintOptions { abortOnError false } if(project.hasProperty("debugSigningPropertiesPath") && project.hasProperty("releaseSigningPropertiesPath")) { File debugPropsFile = new File(System.getenv('HOME') + "/" + project.property("debugSigningPropertiesPath")) File releasePropsFile = new File(System.getenv('HOME') + "/" + project.property("releaseSigningPropertiesPath")) if(debugPropsFile.exists() && releasePropsFile.exists()) { Properties debugProps = new Properties() debugProps.load(new FileInputStream(debugPropsFile)) Properties releaseProps = new Properties() releaseProps.load(new FileInputStream(releasePropsFile)) signingConfigs { debug { storeFile file(debugPropsFile.getParent() + "/" + debugProps['keystore']) storePassword debugProps['keystore.password'] keyAlias debugProps['keyAlias'] keyPassword debugProps['keyPassword'] } release { storeFile file(releasePropsFile.getParent() + "/" + releaseProps['keystore']) storePassword releaseProps['keystore.password'] keyAlias releaseProps['keyAlias'] keyPassword releaseProps['keyPassword'] } } buildTypes { debug { signingConfig signingConfigs.debug } release { signingConfig signingConfigs.release } } } } }
buildscript { repositories { jcenter() maven { url "$ArtifactoryUrl/libs-release-local" credentials { username = ArtifactoryUser password = ArtifactoryPassword } } } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1' classpath 'com.example:android-library-publishing-plugin:1.0' classpath 'com.example:android-signing-plugin:1.0' classpath 'com.example:android-base-plugin:1.0' } } allprojects { repositories { jcenter() maven { url "$ArtifactoryUrl/libs-release-local" credentials { username = ArtifactoryUser password = ArtifactoryPassword } } } } apply plugin: 'com.android.application' apply plugin: 'android-library-publishing' apply plugin: 'android-signing' apply plugin: 'android-base'
Source: https://habr.com/ru/post/267311/
All Articles