How can I tell gradle to execute uploadArchives on a SNAPSHOT release? - maven

I have the following in my build.gradle:
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
String keyFile = "/Users/myusername/.ssh/maven#myhost"
repository(url: "scp://myhost.com/var/maven/repository") {
authentication(userName: "maven", privateKey: keyFile)
}
}
}
}
This works great - with one caveat: It only uploads release builds. I know that I can specify snapshotRepository to get it to upload snapshots, but what I really want is to know how to invoke this behavior. I would like my snapshots to go to the same repo as the release builds (which I think is the default behavior), but when I do:
./gradlew uploadArchives or ./gradlew assembleDebug uploadArchives
it first builds the release buildType, and uploads this. How can I tell uploadArchives I want it to upload the snapshot build (i.e. debug)?

you need to put you versionName with -SNAPSHOT
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0-SNAPSHOT"
}
}
uploadArchives {
repositories.mavenDeployer {
snapshotRepository(url: '.../snapshots') {
authentication(userName: NULL_NEXUS_USER, password: NULL_NEXUS_PWD)
}
repository(url: '.../releases') {
authentication(userName: NULL_NEXUS_USER, password: NULL_NEXUS_PWD)
}
and then ./gradlew clean build uploadFiles will upload it to snaphots repository.

It took me some googling to find a solution so leaving this here for others:
You can make a new task dependent on the uploadArchives task but check the version and remove the dependsOn and disable the task if not a snapshot eg:
task uploadSnapshotArchives(dependsOn: uploadArchives) {
if (!version.endsWith("-SNAPSHOT")) {
enabled = false;
dependsOn = [];
}
}

Related

OpenAPI Generator gradle plugin task not executed

In my android project I am trying to include the openapi-generator plugin to generate a client. I've copied the instructions from the readme for my project. Unfortunately, the task doesen't seem to be executed.
I am new to gradle and android. So I haven't a lot of knowledge on these subjects yet.
This is the projects build.gradle file:
buildscript {
ext {
nav_version = '2.4.2'
}
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.openapitools:openapi-generator-gradle-plugin:5.4.0"
}
}
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is the build.gradle file of my module:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id "org.openapi.generator"
}
android {
compileSdk 31
defaultConfig {
applicationId "..."
minSdk 29
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
dataBinding true
}
sourceSets {
main {
kotlin {
srcDirs += 'build/generated/source/navigation-args/'
}
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
openApiGenerate {
generatorName = "kotlin"
inputSpec = "$rootDir/app/src/main/assets/swagger.yml".toString()
outputDir = "$buildDir/generated".toString()
apiPackage = "org.openapi.example.api"
invokerPackage = "org.openapi.example.invoker"
modelPackage = "org.openapi.example.model"
configOptions = [
dateLibrary: "java8"
]
}
In the output of the build was no hint that the openApiGenerate task was executed and on the filesystem I didn't find the generated client.
Probably there is a mistake in the configuration, but I don't know what is wrong.
Can you help me?
This command should generate the client :
./gradlew openApiGenerate
If you want to avoid manually running this every time your schema changes, then you can go to the drop down here:
Now choose edit configurations:
Now add a gradle task with the + button:
Then:
Enter the task in run:
Now edit the app configuration, by adding what you just created to the before launch section:
You will see the YourAppsName[openApiGenerate] configuration you created as an option, so select that, then apply changes, and now every time you run your application your client will be built.

React Native Project Android Gradle Fail (React-Native-Reanimated Fail)

I was in the middle of coding an app using VS Code and react-native and after trying to install react-native-material-ripple I ran into the following error trying to build my app:
///////////////////////////////////////////////////////////////////////////////////////////////
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\D'errah\Documents\Code\React\dowProjectMatcher\node_modules\react-native-reanimated\android\build.gradle' line: 89
What went wrong:
A problem occurred configuring project ':react-native-reanimated'.
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
//////////////////////////////////////////////////////////////////////////////////////////////
The app was working perfectly before then. I went to the file in question and looked at the line the error mentioned:
mentioned line:
classpath += files(android.bootClasspath)
full file:
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
buildscript {
if (project == rootProject) {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
}
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
}
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "androidx.transition:transition:1.1.0"
}
def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.swmansion.reanimated"
description packageJson.description
url packageJson.repository.baseUrl
licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}
developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}
afterEvaluate { project ->
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
android.libraryVariants.all { variant ->
def compileTask
if (variant.hasProperty('javaCompileProvider')){
compileTask = variant.javaCompileProvider.get()
}else{
compileTask = variant.javaCompile
}
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: compileTask) {
from compileTask.destinationDir
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocJar
}
task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}
}
The problem is, I'm pretty sure that how that line was already even while the app was working. So I've spent the last few hours googling and haven't been able to figure out what cause the issue/how to fix it.
Any help would be GREATLY appreciated!
Things to note:
-using VS Code
-Was working before installing react-native-material-ripple (tried uninstalling, test, reinstalling, test)
Same error occurred for me also, please go through this documentation for proper installation setup for react-native-reanimate.
Install latest
yarn add react-native-reanimated#next
or
npm i react-native-reanimated#next
now go to android dir and gradlew clean, for more details go through below link
https://docs.swmansion.com/react-native-reanimated/docs/installation

Gradle cannot find method android() for arguments (Gradle 2.2.3)

Gradle for my project isn't working. I've checked other questions that have had the same problem, but this one is in a newer version and I'm not sure how to solve it. I'm trying to get the Android SDK up and running for the first time, so I'm really new to this. Thorough answers are appreciated.
Here is my Gradle error:
Error:(22, 0) Could not find method android() for arguments [build_3bh8pl96cp64yo421v01fuk9s$_run_closure3#4b7fff2f] on root project 'Meet-upProject' of type org.gradle.api.Project.
And here is my build.gradle in root:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile files('app/libs/junit-4.12-JavaDoc.jar')
}

Could not find property 'plugin' on project:

I have an SDK for which I've developed a number of small test applications. These are all stand alone android apps which have the following in common:
1) All dependencies are the same (i.e. same version of my sdk/android sdk/etc..)
2) They all share a common top level build.gradle file (which is currently empty):
3) They're build,test etc.. phases are all identical.
I want the projects to all exist as modules in Android studio, and I want them to share as much configuration as possible in the top level build.gradle so that I can update the one file and have everything working correctly.
When I add the following to my top level build.gradle:
subprojects {
apply plugin: "android"
repositories {
mavenCentral()
maven {
url "my.repo.com"
credentials {
username "user"
password "pass"
}
}
dependencies {
compile 'com.my.library:my-library:0.0.1'
// compile 'com.google.android.gms:play-services:+'
}
}
}
I get
'could not find property 'plugin' on ':App1' where ':App1' is the first app in settings.gradle, and the build fails.
My goals would be to get the above block and as many other applicable elements in this top level file.
Edit: I've fixed the syntax error (i was missing the :), but I've that leads to a "plugin with id 'android' not found. Generally this would be resolved by adding:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.4'
}
}
allprojects {
repositories {
mavenCentral()
}
}
But that doesn't resolve it in this case.
Edit 2:
final form:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.4'
}
}
allprojects {
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: "android"
repositories {
mavenCentral()
maven {
url "my.repo.com"
credentials {
username "user"
password "pass"
}
}
dependencies {
compile 'com.my.library:my-library:0.0.1'
// compile 'com.google.android.gms:play-services:+'
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
}
That seems to be working correctly.
This is a simple syntactical error. The apply() method takes a Map as argument. Don't forget the colon (:).
apply plugin: 'android'

Android Gradle Build Resource.getIdentifier() always returns 0

I'm getting started on porting my Game over to the new Gradle Build system for Android.
I'm using the Resource.getIdentifier() method to load some resources by name instead of ID. However, ever since switching to the Gradle build, this call always returns 0. The assets are included in the built jar, and the R.class in the dex file contains all of my resources and ID's as expected, so I am at a loss as to explain this. This code worked before I changed to the gradle build. My build.gradle is below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "19"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
TIA.
D'oh! my problem was that Resources.getIdentifer() takes 3 parameters, one of which is the package name. The debug section of my gradle script was tacking on ".debug" to the package name on the device. Solution is to remove the .debug suffix in the build.gradle.

Resources