alexvasilkov / GradleGitDependenciesPlugin

Gradle plugin to add external git repos as project dependencies
Apache License 2.0
105 stars 15 forks source link

Custom build types #4

Closed Ch4t4r closed 4 years ago

Ch4t4r commented 4 years ago

I have one Android app which references 5 libraries using this plugin. I also have custom buildTypes and flavors. When I try to assemble with a default configuration (for instance ./gradlew assembleDebug) it works, if I use a custom build type (for example './gradlew assembleFlavorMyType') it complains that it can't find any matching configuration in the library. It does so for all libraries with a error message to the tune of The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'myType', attribute 'version' with value 'normal', attribute 'com.android.build.gradle.internal.dependency.AndroidTypeAttr' with value 'Aar', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :libraryUsed:

Declaring matchingFallbacks = ['debug'] in the build type does not work. I believe this could be solved by setting the configuration value you can pass with implementation() however this library doesn't allow me to forward the value to the actual declaration of the dependency.

alexvasilkov commented 4 years ago

Hm, I didn't get it. Can you provide the minimum possible code to demonstrate the issue?

So far it sounds like you need to properly sinchronize build types and flavors across your modules, but this plugin has nothing to do with it.

Basically you can just manually clone all your modules and then include them as usual modules in settings.gradle. This will be equivalent to using this plugin. Once you can make your modules work with each other you can use this plugin to automate clonning stuff, but this time it should work fine.

Ch4t4r commented 4 years ago

Sure This'd be the module-level build.gradle.

android {
 [...]
 buildTypes {
   release { [...] }
   myType {
      matchingFallbacks = ['release']
      initWith release
   } 
 }
 flavorDimensions "version"
 productFlavors {
    myFlavor { [...] }
 }
}
git {
  implementation "https://git.example.com/group/artifact.git", {
     projectPath "/library"
  }
}

The library added via git{} contains neither this build type, nor the flavor. From my understanding it shouldn't, as then the library would need to know about the project using it (or did you mean something different with "So far it sounds like you need to properly sinchronize build types and flavors across your modules"?).

When now executing ./gradlew assembleDebug it properly compiles, creating a debug APK. When however trying to use ./gradlew assembleMyFlavorMyType it produces the error I've shown above. It looks like it tries to locate the build type in the library but fails. I believe I could normally fix this by using implementation('group:artifact:version', configuration: 'release') but I see no way to pass the configuration: 'release' bit (and if there's one let me know)

I'm hesitant to change the library modules to include the build type as it would mirror the app's build types. Maybe I'm missing something here?

alexvasilkov commented 4 years ago

Here:

   myType {
      matchingFallbacks = ['release']
      initWith release
   } 

I think that the order is not correct, initWith method call will override matchingFallbacks so it will become empty. Make sure that initWith is called first.

I believe I could normally fix this by using implementation('group:artifact:version', configuration: 'release')

Hm, I'm not aware of such syntaxis when declaring dependencies, can you provide a link to corresponding documentation? It looks quite weird because implementation is already a configuration name so passing extra configuration: 'release' has little sense to me.

Overall it looks like you a mixing "configurations" which come from Gradle and "build variants" (build type + flavor) that comes from Android Gradle plugin. And both of them are not related to git dependencies plugin.

As I said you can completely remove this plugin, clone your repos and add them as dependencies manually. As soon as you can make it work like you won't have problems using this plugin as well.

gabrielfeo commented 4 years ago

I believe I could normally fix this by using implementation('group:artifact:version', configuration: 'release') but I see no way to pass the configuration: 'release' bit (and if there's one let me know)

I think what you mean is to prefix the standard configuration name with the name of your build variant:

releaseImplementation 'group:artifact:version'

https://developer.android.com/studio/build/build-variants#dependencies