In my pom file I have one artifact like below:
<artifactItem>
<groupId>com.xyz</groupId>
<artifactId>xyz.abc</artifactId>
<version>1.0</version>
<classifier>pqr</classifier>
<type>js</type>
<overWrite>true</overWrite>
<outputDirectory>/opt/test</outputDirectory>
<destFileName>test.js</destFileName>
</artifactItem>
How to implement this in my build.gradle. I am using gradle 2.6.
Sorry, I cannot post original code so put some unrealistic values. Please reply
WIth gradle you can use the maven plugin.
You can find the full doc for the 2.6 here.
I don't know if you can set all attributes, but you can use a script like this:
apply plugin: 'maven'
apply plugin: 'signing'
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: "...") {
authentication(userName: "user", password: "pass")
}
snapshotRepository(url: "...") {
authentication(userName: "user", password: "pass")
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { true }
sign configurations.archives
}
artifacts {
archives xxxx
}
}
i created a gradle task
task test <<{
copy {
from --dir---
into --dir--
rename { String fileName ->
fileName.replace("xyz.abc-$1.0-pqr","user-prefs")
}
}
}
It worked for me.
Related
I am trying to build a script to publish APK artifacts to Nexus using the "maven-publish" plugin.
In Gradle 4 it was possible to have a configuration like this (this works):
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
credentials {
username mavenUser
password mavenPassword
}
}
publications {
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
if (variant.name == "release") {
create("apk${variant.name.capitalize()}", MavenPublication) {
groupId project.group
artifactId project.name
version project.version
artifact(output.outputFile)
}
}
}
}
}
}
}
In Gradle 5 this is no longer possible
When trying to build the project I get this error:
Cannot create a Publication named 'android' because this container does not support creating elements by name alone. Please specify which subtype of Publication to create. Known subtypes are: MavenPublication
How can I rewrite this code to be compatible with Gradle 5?
Another option for building arbitrary variants (tested on Gradle 5.5.1 / Android Gradle 3.5.0):
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
credentials {
username mavenUser
password mavenPassword
}
}
publications {
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
"maven${variant.name.capitalize()}Apk"(MavenPublication) {
groupId project.group
artifactId project.name
version project.version
artifact(output.outputFile)
}
}
}
}
}
}
Example of resulting publish task when building with debug variant: publishMavenDebugApkPublicationToMavenRepository
I found something that works (equivalent to my code example above):
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url "https://$MY_NEXUS_SERVER$/repository/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}"
credentials {
username mavenUser
password mavenPassword
}
}
publications {
create("apkRELEASE", MavenPublication) {
afterEvaluate {
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
if (variant.name == "release") {
groupId project.group
artifactId project.name
version project.version
artifact(output.outputFile)
}
}
}
}
}
}
}
}
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
Hi am getting the following error while adding facebook sdk to my project
Tried the following post for configuring the gradle script for facebook sdk
link
Error:(111) A problem occurred evaluating project ':facebook'.
> Cannot call getBootClasspath() before setTargetInfo() is called.
This is my facebook module gradle script
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
compile 'com.android.support:support-v4:[21,22)'
compile 'com.parse.bolts:bolts-android:1.1.4'
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
minSdkVersion 18
targetSdkVersion 22
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
apply plugin: 'maven'
apply plugin: 'signing'
def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
task setVersion {
// The version will be derived from source
project.version = null
def sdkVersionFile = file('src/com/facebook/FacebookSdkVersion.java')
sdkVersionFile.eachLine{
def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
if (matcher.matches()) {
project.version = matcher[0][2]
return
}
}
if (project.version.is('unspecified')) {
throw new GradleScriptException('Version could not be found.', null)
}
}
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Facebook-Android-SDK'
artifactId = 'facebook-android-sdk'
packaging 'aar'
description 'Facebook Android SDK'
url 'https://github.com/facebook/facebook-android-sdk'
scm {
connection 'scm:git#github.com:facebook/facebook-android-sdk.git'
developerConnection 'scm:git#github.com:facebook/facebook-android-sdk.git'
url 'https://github.com/facebook/facebook-android-sdk'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
}
uploadArchives.dependsOn(setVersion)
signing {
required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}
Please help....
Your issue: Cannot call getBootClasspath() before setTargetInfo() is called., I believe has been solved here:
http://tools.android.com/tech-docs/new-build-system
Android Build tools 1.1.0 created this problem and they fixed it in 1.1.1:
1.1.1 (2015/02/24)
Only variants that package a Wear app will now trigger building them.
Dependency related issues now fail at build time rather than at debug time.
This is to allow running diagnostic tasks (such as 'dependencies') to help resolve the conflict.
Calling android.getBootClasspath() is now possible again.
Please upgrade to: classpath 'com.android.tools.build:gradle:1.2.3', for example:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
I have problem with gradle in Android Studio 0.5.2.
It's shown below:
Could not find com.android.support:support-v4:19.0.0.
Required by:
org.codepond:wizardroid:1.2.0
Please install the Android Support Repository from the Android SDK Manager.
I Also Installed Android Support Repository.
My build.gradle looks like this:
apply plugin: 'android-library'
apply plugin: 'android-maven'
apply plugin: 'signing'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode project.ext.versionCode
versionName version
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
boolean hasCredentials = hasProperty('sonatypeUsername') && hasProperty('sonatypeUsername')
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
if (hasCredentials) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
if (hasCredentials) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
pom.project {
name 'WizarDroid'
description 'Lightweight Android library for creating step by step wizards'
url 'http://wizardroid.codepond.org'
scm {
url 'http://www.github.com/nimrodda/wizardroid'
connection 'scm:git://github.com/Nimrodda/WizarDroid.git'
developerConnection 'scm:git://github.com/Nimrodda/WizarDroid.git'
}
licenses {
license {
name 'The MIT License (MIT)'
url 'https://raw.github.com/Nimrodda/WizarDroid/master/license'
distribution 'repo'
}
}
developers {
developer {
id 'nimrodda'
name 'Nimrod Dayan'
email 'feedback#codepond.org'
}
}
organization {
name 'CodePond.org'
url 'http://www.codepond.org'
}
issueManagement {
system 'GitHub Issues'
url 'https://github.com/nimrodda/wizardroid/issues'
}
parent {
groupId 'org.sonatype.oss'
artifactId 'oss-parent'
version 7
}
}
}
}
}
You should change build.gradle to
dependencies {
compile 'com.android.support:support-v4:19.1.+'
}
I'd like to split up a module (library) in two modules (lib-core) and (lib-extras).
Currently, I'm publishing with artifact id library, and I want to keep this functionality as well. I also want to publish the two separate modules.
For example:
lib-core
class A
lib-extras
class B
library
*(empty, depends on lib-core and lib-extras)*
What I want to achieve is when publishing these modules, I get an archive lib-core containing class A, and archive lib-extras containing class B, and an archive library, containing both classes A and B.
Is this possible using gradle?
This is my uploadArchives task, which is applied in all three modules:
apply plugin: 'maven'
apply plugin: 'signing'
def sonatypeRepositoryUrl
if (isRelease == 'true') {
sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
version = VERSION_NAME + '-SNAPSHOT'
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.artifactId = POM_ARTIFACT_ID
repository(url: sonatypeRepositoryUrl) {
authentication(userName: nexusUsername, password: nexusPassword)
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isRelease == 'true' && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java
}
task androidJavadocsJar(type: Jar) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
}