ysb33r / ivypot-gradle-plugin

Ivypot is a Gradle plugin to help managing a local off-line repository for builds in restricted environments
Apache License 2.0
45 stars 14 forks source link

Building offlline fails because it is unable to find aapt2 ( com.android.tools.build:aapt2:3.3.2-5309881) #39

Closed devhandle closed 4 years ago

devhandle commented 5 years ago

I'm struggling to get the plugin to work with my project. My project is a simple test project with a single app. Running ./gradlew syncRemoteRepositories succeeds and creates a repo directory under my project (myapp/repo) but when I run ./gradlew assembleDebug --offline I see the error message below. The error is correct because the location does not exist in my offline repo - the only 'aapt2' folder is this one file:/myapp/repo/com.android.tools.build/aapt2-proto/0.3.1/

Any ideas on how I can fix this because I've been fighting with it for last few days. I've also pasted my build.gradle below

* What went wrong:
Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
> Could not find com.android.tools.build:aapt2:3.3.2-5309881.
  Searched in the following locations:
    - file:/home/android/Android/SDK/extras/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881.pom
    - file:/home/android/Android/SDK/extras/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881-linux.jar
    - file:/home/android/Android/SDK/extras/google/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881.pom
    - file:/home/android/Android/SDK/extras/google/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881-linux.jar
    - file:/home/android/Android/SDK/extras/android/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881.pom
    - file:/home/android/Android/SDK/extras/android/m2repository/com/android/tools/build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881-linux.jar
    - file:/myapp/repo/com.android.tools.build/aapt2/3.3.2-5309881/ivy-3.3.2-5309881.xml
    - file:/myapp/repo/com.android.tools.build/aapt2/3.3.2-5309881/aapt2-3.3.2-5309881-linux.jar
  Required by:
      project :app
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        if(gradle.startParameter.isOffline()) {
            println "OFFLINE: using local cache: ${rootProject.projectDir}/repo"
            ivy { url file("${rootProject.projectDir}/repo").toURI() }
        } else {
            jcenter()
            google()
            mavenCentral()
            mavenLocal()
            maven { url "https://plugins.gradle.org/m2/" }
      }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id "org.ysb33r.ivypot" version "0.9"
}

allprojects {
    repositories {

        if(gradle.startParameter.isOffline()) {
            println "OFFLINE: allprojects using local cache: ${rootProject.projectDir}/repo"
            ivy { url file("${rootProject.projectDir}/repo").toURI() }
        } else {
            jcenter()
            google()            
            mavenCentral()
            mavenLocal()
            maven { url "https://plugins.gradle.org/m2/" }
      }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    thisProject = project.name
    addConfigurationsFor = { Project forProj ->
        if( forProj != project ) {
            forProj.configurations.each { Configuration c->
                logger.info "${forProj.name}: ${c.name}"
                String configName = "${forProj.name}_${c.name}_deps"
                project.configurations.create configName
                project.syncRemoteRepositories.configurations configName
                c.dependencies.each { Dependency d ->
                    logger.info "Found ${d} in ${forProj.name}. Adding to ${configName}"
                    project.dependencies.add configName, d
                }
            }
            forProj.childProjects.each { String projName, Project p ->
                addConfigurationsFor(p)
            }
        }
    }
}

addConfigurationsFor(rootProject)

syncRemoteRepositories {
    repoRoot = "${rootProject.projectDir}/repo"

    repositories {
            jcenter()
            google()
            mavenCentral()
            mavenLocal()
            maven { url "https://plugins.gradle.org/m2/" }
    }

    onlyIf { !gradle.startParameter.isOffline() }
    includeBuildScriptDependencies = true
}
ysb33r commented 5 years ago

Most of what you are trying to do here...

    addConfigurationsFor = { Project forProj ->
        if( forProj != project ) {
            forProj.configurations.each { Configuration c->
                logger.info "${forProj.name}: ${c.name}"
                String configName = "${forProj.name}_${c.name}_deps"
                project.configurations.create configName
                project.syncRemoteRepositories.configurations configName
                c.dependencies.each { Dependency d ->
                    logger.info "Found ${d} in ${forProj.name}. Adding to ${configName}"
                    project.dependencies.add configName, d
                }
            }
            forProj.childProjects.each { String projName, Project p ->
                addConfigurationsFor(p)
            }
        }
    }

... can probably be achieved by simply doing syncRemoteProjects.addAllProjects()

ysb33r commented 4 years ago

Closing this as it has been open for a long time and the suggestion should have solved the problem.