How to migrate from maven to maven-publish

Viewed 2504

I am trying to make Android App bundles for Google Play using Android Studio. Android Studio told that I need to upgrade Gradle for that. I migrated Gradle to 7.0.0 version (and updated Android Studio itself), but I am totally new in this, so now I have issues with Maven. I got the following error:

Build file '/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle' line: 2

A problem occurred evaluating project ':expo-application'.

Plugin with id 'maven' not found.

I found that maven is not used anymore, so I need to migrate to maven-publish. I changed maven to maven-publish, but now I have the following issue:

Build file '/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle' line: 28

A problem occurred evaluating project ':expo-application'.

Could not find method uploadArchives() for arguments [build_6lgwxdh9lx7r2mkhkk2he2s1g$_run_closure4@56af98de] on project ':expo-application' of type org.gradle.api.Project.

The build.gradle file with the issue looks like that:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

group = 'host.exp.exponent'
version = '3.1.2'

// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Upload android library to maven with javadoc and android sources
configurations {
  deployerJars
}

// Creating sources with comments
task androidSourcesJar(type: Jar) {
  classifier = 'sources'
  from android.sourceSets.main.java.srcDirs
}

// Put the androidSources and javadoc to the artifacts
artifacts {
  archives androidSourcesJar
}

uploadArchives {
  repositories {
    mavenDeployer {
      configuration = configurations.deployerJars
      repository(url: mavenLocal().url)
    }
  }
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 30)

  defaultConfig {
    minSdkVersion safeExtGet("minSdkVersion", 21)
    targetSdkVersion safeExtGet("targetSdkVersion", 30)
    versionCode 12
    versionName '3.1.2'
  }
  lintOptions {
    abortOnError false
  }
}

if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
  apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
  throw new GradleException(
      '\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
          'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}

dependencies {
  unimodule 'unimodules-core'
  implementation 'com.android.installreferrer:installreferrer:1.0'
}

So, the question is: how to fix the new issue?

Update. I read the article from the comment, and now the file looks like this:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Upload android library to maven with javadoc and android sources
configurations {
  deployerJars
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release

                groupId = 'host.exp.exponent'
                artifactId = 'noughts-and-crosses'
                version = '3.1.2'
                artifact(sourcesJar)
            }
        }
    }
}

uploadArchives {
  repositories {
    mavenDeployer {
      configuration = configurations.deployerJars
      repository(url: mavenLocal().url)
    }
  }
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 30)

  defaultConfig {
    minSdkVersion safeExtGet("minSdkVersion", 21)
    targetSdkVersion safeExtGet("targetSdkVersion", 30)
    versionCode 12
    versionName '3.1.2'
  }
  lintOptions {
    abortOnError false
  }
}

if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
  apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
  throw new GradleException(
      '\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
          'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}

dependencies {
  unimodule 'unimodules-core'
  implementation 'com.android.installreferrer:installreferrer:1.0'
}

But it didn't solve the problem.

0 Answers
Related