I want to publish some subproject to maven by using maven-publish plugin. The current Gradle script looks like this.
apply plugin: 'maven-publish'
group "com.huawei.quickapp"
version "1.0-SNAPSHOT"
publishing {
publications {
publishTask(MavenPublication) {
}
}
repositories {
maven {
url = uri("${rootDir}/local_repo/repos/")
}
}
}
}
static Boolean publishIfNeeded(taskName){
println("name = " + taskName)
def list = ["baselibrary", "corelibrary"]
if (taskName in list) {
return true
}
return false
}
I just want two libraries,core and base to be published. When I submitted the code to the pipeline, the CI suggested that the NDK version did not match, but there was no NDK-related configuration in my code. The upgrade is necessary because only versions greater than 3.6 support the use of From Components.Debug or some other build variable in gradle script.I tried configuring the build script for Subproject separately like this:
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.5.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
subprojects {
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
}
}
}
but it still not work. I got this error
Could not get unknown property 'Debug' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
Is there a way to publish a submodule using the buildScripte of a submodule? thx.
Related
I use Gradle Kotlin DSL and in my project I have separate build-dependencies gradle module which is included in settings.gradle.kts like so:
pluginManagement {
repositories {
google()
jcenter()
gradlePluginPortal()
}
}
includeBuild("build-dependencies")
This module contains empty plugin implementation and Deps object. Its build.gradle.kts below:
repositories {
google()
jcenter()
gradlePluginPortal()
}
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
gradlePlugin {
plugins.register("com.example.dependencies") {
id = "com.example.dependencies"
implementationClass = "com.example.dependencies.DependenciesPlugin"
}
}
Deps object:
object Deps {
const val buildTools = "com.android.tools.build:gradle:4.1.1"
// more dependencies
}
I want to use this Deps object in all modules by applying the plugin in build.gradle.kts files.
plugins {
id("com.example.dependencies")
}
And it works fine, I can import and use Deps object.
But there is a problem when I want to use it in root projects build.gradle.kts and more precisely in buildscript like so:
buildscript {
repositories {
google()
jcenter()
}
plugins {
id("com.example.dependencies")
}
dependencies {
classpath(com.example.dependencies.Deps.buildTools) // It doesn't work
}
}
Is there any way to use a custom plugin inside buildscript like this or could you suggest something to replace this approach?
I also wonder this. However, I think this is the difference between includeBuild and buildSrc.
I have JFrog Open Source installed on a server and upload an android aar library by hand.
In the gradle file, I set up a configuration like this.
buildscript {
dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release" }
repositories {
maven {
credentials {
username = artifactory_username
password = artifactory_password
}
url "https://.../artifactory/libs-release"
}
}
}
allprojects{
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
artifactory {
resolve {
contextUrl = "https://.../artifactory"
repoKey = 'libs-global'
username = artifactory_username
password = artifactory_password
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
apply plugin: "com.jfrog.artifactory"
QUESTION:
How can download or implement my aar libary in the android project?
Example:
implementation 'com.google.code.gson:gson:2.8.6'
You need to add your Jfrog in build.gradle(project) like this:
allprojects {
repositories {
...
maven {
url("https://your-url.jfrog.com/more/path")
}
google()
jcenter()
...
}
}
Then you just add your dependency in dependencies.
I have an android project which includes 3 modules ModuleA, ModuleB, ModuleC. ModuleA depends on both ModuleB and ModuleC. I'm trying to publish the ModuleA to a maven repository using android-maven-publish plugin and looks like it is not automatically publishing ModuleB and ModuleC to maven when I run publishToMavenLocal. When I try to use published ModuleA as a dependency in a different project gradle could not resolve ModuleB, ModuleC.
Is there something that I am missing?.
I am using gradle plugin version 3.5.0, gradle version 5.4.1 and mavenPublishVersion 3.6.2.
This is how project's gradle looks like
build.gradle(project)
buildScript {
...
dependencies {
classpath "digital.wup:android-maven-publish:3.6.2"
}
}
allprojects {
apply plugin: "digital.wup.android-maven-publish"
}
and ModuleA's build.gradle
build.gradle(ModuleA)
...
dependencies {
api project(":moduleB")
api project(":moduleC")
}
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleA(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleA"
version = "1.0.0"
}
}
}
and ModuleB's build.gradle
build.gradle(ModuleB)
...
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleB(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleB"
version = "1.0.0"
}
}
}
and ModuleC's build.gradle
build.gradle(ModuleC)
...
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleC(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleC"
version = "1.0.0"
}
}
}
I've copied exactly what the kotlin gradle docs say to implement kotlin gradle plugin, however it's returning the following error:
Could not find method kotlin() for arguments [gradle-plugin, 1.3.20] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
my gradle
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath(kotlin("gradle-plugin", version = "1.3.20"))
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// ext {
// navigationVersion = '28.0.0'
// }
plugins {
kotlin("<...>")
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any idea?
build.gradle can be written in Groovy or Kotlin. You're typing your build.gradle in Groovy (not Kotlin), but you have copied the Kotlin code. You should select the Groovy tab on the documentation:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.3.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
Here: https://kotlinlang.org/docs/reference/using-gradle.html#targeting-android
You can also find a decent example by creating an empty Android and Kotlin project.
I am trying to setup the artifacts (APK/aar files) build process with gradle similar to how I am used to with maven.
mvn release:prepare (Adjusts version, checks into SVN, creates the tag)
mvn release:perform -Dgoals=deploy (Pushes the artifact to http://artifactory.XXX.local/artifactory/libs-releases-local/)
I want to be able to run the gradle commands and achieve similar results. I am using https://github.com/researchgate/gradle-release plugin for the release management (which works fine so I am good with release). But when I run the command gradlew artifactoryPublish the artifact is deployed at some other location (as if it's not respecting the repoKey in the gradle file)
D:\my-lib-android-0.0.2>gradlew artifactoryPublish ... ... [buildinfo]
Not using buildInfo properties file for this build.
:artifactoryPublish Deploying build descriptor to:
http://artifactory.XXX.local/artifactory/api/build Build successfully
deployed. Browse it in Artifactory under
http://artifactory.XXX.local/artifactory/webapp/builds/my-lib-android-0.0.2/1449880830949>
BUILD SUCCESSFUL
Total time: 9.692 secs
So my question is how can I fix my setup so that the artifact is pushed to a URL similar to this:
http://artifactory.XXX.local/artifactory/libs-releases-local/com/example/my-lib-android/0.0.2/my-lib-android-0.0.2.aar
build.gradle File:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.2')
classpath 'net.researchgate:gradle-release:2.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'net.researchgate.release' version '2.3.4'
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply plugin: 'net.researchgate.release'
allprojects {
repositories {
jcenter()
maven {
url 'http://artifactory.XXX.local/artifactory/libs-releases-local'
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
//The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = "libs-releases-local"
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
release {
revertOnFail = false
}
task build{
}
gradle.properties File:
version=my-lib-android-0.0.3-SNAPSHOT
artifactory_user=myUserName
artifactory_password=myPasssword
artifactory_contextUrl=http://artifactory.XXX.local/artifactory
Using android-maven plugin:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'com.github.dcendents:android-maven-plugin:1.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.2.0'
}
}
apply plugin: 'android-library'
apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'android-maven'
configurations {
published
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java
classifier "sources"
}
artifactoryPublish {
dependsOn sourceJar
}
artifacts {
published sourceJar
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = "libs-releases-local"
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publishConfigs('archives', 'published')
publishPom = true //Publish generated POM files to Artifactory (true by default)
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
}
I usually do it with the mavenDeployer-plugin like this.
Don't know if it matches your case, but I'll just leave it here.
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/releases') {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
}
snapshotRepository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/snapshots') {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
}
pom.groupId = "groupId"
pom.artifactId = "artifactId"
pom.version = "${versionMajor}.${versionMinor}.${versionPatch}"
}
}
}
some further reading for local repos here