gaelmarhic / Quadrant

A Gradle plugin for Android that makes navigation easy in multi-module projects.
Apache License 2.0
216 stars 13 forks source link

build: declare dependency from KSP #15

Closed MasaHirano closed 10 months ago

MasaHirano commented 10 months ago

Overview:

I find this plugin helpful while I migrate my app to a single-activity architecture. I use KSP for annotation processing but the build fails due to a missing dependency declaration.

* What went wrong:
A problem was found with the configuration of task ':<my-module>:kspDebugKotlin' (type 'KspTaskJvm').
  - Gradle detected a problem with the following location: '<my-module-path>/build/generated/source/quadrant'.

    Reason: Task ':<my-module>:kspDebugKotlin' uses this output of task ':<my-module>:generateActivityClassNameConstants' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':<my-module>:generateActivityClassNameConstants' as an input of ':<my-module>:kspDebugKotlin'.
      2. Declare an explicit dependency on ':<my-module>:generateActivityClassNameConstants' from ':<my-module>:kspDebugKotlin' using Task#dependsOn.
      3. Declare an explicit dependency on ':<my-module>:generateActivityClassNameConstants' from ':<my-module>:kspDebugKotlin' using Task#mustRunAfter.

    For more information, please refer to https://docs.gradle.org/8.4/userguide/validation_problems.html#implicit_dependency in the Gradle documentation.

Dear @gaelmarhic, I don't know if you still maintain this repository but if you can have time to look at this PR, it's highly appreciated.

gaelmarhic commented 10 months ago

Hey @alpaca0984! Thanks for your interest in Quadrant and for your PR! Could you provide the detailed steps of how to reproduce the issue myself (or a sample project)? Once I can reproduce it, I'll look at the PR and test it! Thanks again!

MasaHirano commented 10 months ago

Hello @gaelmarhic, thank you for your reply :)

I created a sample project where I could see the build error. https://github.com/alpaca0984/QuadrantKspCompileSample It imports this Quadrant plugin and also uses the KSP for the Glide plugin. Once you run "Make Project", you should be able to see the error.

My environment is:

Let me know if you need more information. Many thanks

gaelmarhic commented 10 months ago

Hi @alpaca0984!

Thanks for providing the sample project.

I have been able to reproduce this issue and test your fix.

I have merged the PR and published a new version (1.8). It is still pending for approval from Gradle.

I'll let you know once it is available.

Thanks for your contribution!

MasaHirano commented 10 months ago

Hello @gaelmarhic, Thank you for publishing the new version.

Besides this PR, I found that this project needs to be updated to support partially qualified class names (related to #3 ). From Android Gradle Plugin 7.3.0, package attribute in manifest file is deprecated. https://developer.android.com/build/releases/past-releases/agp-7-3-0-release-notes#package-deprecated

I will open another PR in several days :)

gaelmarhic commented 10 months ago

Hi @alpaca0984, The new version has not been approved yet. Feel free to track it here: https://plugins.gradle.org/plugin/com.gaelmarhic.quadrant.

gaelmarhic commented 10 months ago

Thanks for noticing that!

Looking forward to your PR!

Thank you for your interest and for the help! :)

gaelmarhic commented 10 months ago

Hey @alpaca0984. Version 1.8 was finally published!

I wanted to test it against your sample project, but I can't build it because of the following error:

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugKotlin'.
> No matching toolchains found for requested specification: {languageVersion=8, vendor=any, implementation=vendor-specific}.
   > No locally installed toolchains match (see https://docs.gradle.org/8.0/userguide/toolchains.html#sec:auto_detection) and toolchain download repositories have not been configured (see https://docs.gradle.org/8.0/userguide/toolchains.html#sub:download_repositories).

I saw that you made some changes regarding the toolchain in the last few days.

Does it build on your side?

Thanks!

MasaHirano commented 9 months ago

Hi @gaelmarhic ,

On my end, I can build the sample project with Quadrant 1.8. I use Java 17.0.7 for build.

Build logs are here ``` Executing tasks: [:app:assembleDebug, :module1:assembleDebug, :module2:assembleDebug] in project /Users//StudioProjects/QuadrantKspCompilesSample Starting Gradle Daemon... Gradle Daemon started in 492 ms Configuration 'kspDebugKotlinProcessorClasspath' was resolved during configuration time. This is a build performance and scalability issue. See https://github.com/gradle/gradle/issues/2298 Run with --info for a stacktrace. > Task :app:createDebugVariantModel UP-TO-DATE > Task :app:preBuild UP-TO-DATE > Task :app:preDebugBuild UP-TO-DATE > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE > Task :app:checkDebugAarMetadata UP-TO-DATE > Task :app:generateDebugResValues UP-TO-DATE > Task :app:mapDebugSourceSetPaths UP-TO-DATE > Task :app:generateDebugResources UP-TO-DATE > Task :app:mergeDebugResources UP-TO-DATE > Task :app:packageDebugResources UP-TO-DATE > Task :app:parseDebugLocalResources UP-TO-DATE > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE > Task :app:extractDeepLinksDebug UP-TO-DATE > Task :app:processDebugMainManifest UP-TO-DATE > Task :app:processDebugManifest UP-TO-DATE > Task :app:processDebugManifestForPackage UP-TO-DATE > Task :app:processDebugResources UP-TO-DATE > Task :app:kspDebugKotlin UP-TO-DATE > Task :app:compileDebugKotlin UP-TO-DATE > Task :app:javaPreCompileDebug UP-TO-DATE > Task :app:compileDebugJavaWithJavac NO-SOURCE > Task :app:mergeDebugShaders UP-TO-DATE > Task :app:compileDebugShaders NO-SOURCE > Task :app:generateDebugAssets UP-TO-DATE > Task :app:mergeDebugAssets UP-TO-DATE > Task :app:compressDebugAssets UP-TO-DATE > Task :app:processDebugJavaRes UP-TO-DATE > Task :app:mergeDebugJavaResource UP-TO-DATE > Task :app:checkDebugDuplicateClasses UP-TO-DATE > Task :app:desugarDebugFileDependencies UP-TO-DATE > Task :app:mergeExtDexDebug UP-TO-DATE > Task :app:mergeLibDexDebug UP-TO-DATE > Task :app:dexBuilderDebug UP-TO-DATE > Task :app:mergeProjectDexDebug UP-TO-DATE > Task :app:mergeDebugJniLibFolders UP-TO-DATE > Task :app:mergeDebugNativeLibs NO-SOURCE > Task :app:stripDebugDebugSymbols NO-SOURCE > Task :app:validateSigningDebug UP-TO-DATE > Task :app:writeDebugAppMetadata UP-TO-DATE > Task :app:writeDebugSigningConfigVersions UP-TO-DATE > Task :app:packageDebug UP-TO-DATE > Task :app:createDebugApkListingFileRedirect UP-TO-DATE > Task :app:assembleDebug UP-TO-DATE > Task :module1:preBuild UP-TO-DATE > Task :module1:preDebugBuild UP-TO-DATE > Task :module1:mergeDebugJniLibFolders UP-TO-DATE > Task :module1:mergeDebugNativeLibs NO-SOURCE > Task :module1:stripDebugDebugSymbols NO-SOURCE > Task :module1:copyDebugJniLibsProjectAndLocalJars UP-TO-DATE > Task :module1:generateActivityClassNameConstants UP-TO-DATE > Task :module1:generateDebugResValues UP-TO-DATE > Task :module1:generateDebugResources UP-TO-DATE > Task :module1:packageDebugResources UP-TO-DATE > Task :module1:parseDebugLocalResources UP-TO-DATE > Task :module1:processDebugManifest UP-TO-DATE > Task :module1:generateDebugRFile UP-TO-DATE > Task :module1:compileDebugKotlin UP-TO-DATE > Task :module1:extractDebugAnnotations UP-TO-DATE > Task :module1:extractDeepLinksForAarDebug UP-TO-DATE > Task :module1:javaPreCompileDebug UP-TO-DATE > Task :module1:compileDebugJavaWithJavac NO-SOURCE > Task :module1:mergeDebugGeneratedProguardFiles UP-TO-DATE > Task :module1:mergeDebugConsumerProguardFiles UP-TO-DATE > Task :module1:mergeDebugShaders UP-TO-DATE > Task :module1:compileDebugShaders NO-SOURCE > Task :module1:generateDebugAssets UP-TO-DATE > Task :module1:packageDebugAssets UP-TO-DATE > Task :module1:prepareDebugArtProfile UP-TO-DATE > Task :module1:prepareLintJarForPublish UP-TO-DATE > Task :module1:processDebugJavaRes UP-TO-DATE > Task :module1:mergeDebugJavaResource UP-TO-DATE > Task :module1:syncDebugLibJars UP-TO-DATE > Task :module1:writeDebugAarMetadata UP-TO-DATE > Task :module1:bundleDebugAar UP-TO-DATE > Task :module1:createDebugVariantModel UP-TO-DATE > Task :module1:assembleDebug UP-TO-DATE > Task :module2:preBuild UP-TO-DATE > Task :module2:preDebugBuild UP-TO-DATE > Task :module2:mergeDebugJniLibFolders UP-TO-DATE > Task :module2:mergeDebugNativeLibs NO-SOURCE > Task :module2:stripDebugDebugSymbols NO-SOURCE > Task :module2:copyDebugJniLibsProjectAndLocalJars UP-TO-DATE > Task :module2:generateDebugResValues UP-TO-DATE > Task :module2:generateDebugResources UP-TO-DATE > Task :module2:packageDebugResources UP-TO-DATE > Task :module2:parseDebugLocalResources UP-TO-DATE > Task :module2:processDebugManifest UP-TO-DATE > Task :module2:generateDebugRFile UP-TO-DATE > Task :module2:compileDebugKotlin UP-TO-DATE > Task :module2:extractDebugAnnotations UP-TO-DATE > Task :module2:extractDeepLinksForAarDebug UP-TO-DATE > Task :module2:javaPreCompileDebug UP-TO-DATE > Task :module2:compileDebugJavaWithJavac NO-SOURCE > Task :module2:mergeDebugGeneratedProguardFiles UP-TO-DATE > Task :module2:mergeDebugConsumerProguardFiles UP-TO-DATE > Task :module2:mergeDebugShaders UP-TO-DATE > Task :module2:compileDebugShaders NO-SOURCE > Task :module2:generateDebugAssets UP-TO-DATE > Task :module2:packageDebugAssets UP-TO-DATE > Task :module2:prepareDebugArtProfile UP-TO-DATE > Task :module2:prepareLintJarForPublish UP-TO-DATE > Task :module2:processDebugJavaRes UP-TO-DATE > Task :module2:mergeDebugJavaResource UP-TO-DATE > Task :module2:syncDebugLibJars UP-TO-DATE > Task :module2:writeDebugAarMetadata UP-TO-DATE > Task :module2:bundleDebugAar UP-TO-DATE > Task :module2:createDebugVariantModel UP-TO-DATE > Task :module2:assembleDebug UP-TO-DATE BUILD SUCCESSFUL in 8s 80 actionable tasks: 80 up-to-date Build Analyzer results available ```

I saw that you made some changes regarding the toolchain in the last few days.

Yes, I made the changes to address an error raised by the Android Studio. I use the KSP in the app module.

Execution failed for task ':app:kspDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kspDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

Let me know if you need further information. I will be happy to jump in.

MasaHirano commented 9 months ago

Apparently, ↓ is the specific issue with KSP 1.8.XX.

Execution failed for task ':app:kspDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kspDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

I updated it from 1.8.10-1.0.9 to 1.9.0-1.0.13 with alpaca0984/QuadrantKspCompileSample#1 and now kotlinOptions.jvmTarget works as expected.

Also, I configured GitHub actions to confirm the build succeeds. https://github.com/alpaca0984/QuadrantKspCompileSample/actions/runs/7307638930/job/19913531756

gaelmarhic commented 9 months ago

Hey @alpaca0984! I downloaded the latest version of your repo and was finally able to test 1.8. Thanks for fixing it :)

MasaHirano commented 9 months ago

Hi @gaelmarhic and Happy New Year 🎉

You're welcome. You might notice that although build succeeds, the Quadrant failed to create fully qualified class names.

package com.gaelmarhic.quadrant

import kotlin.String

public object QuadrantConstants {
  public const val MAIN_ACTIVITY: String = ".MainActivity"

  public const val ACTIVITY1: String = ".Activity1"

  public const val ACTIVITY2: String = ".Activity2"
}

It should be fixed with #16 .

gaelmarhic commented 9 months ago

Hi @alpaca0984! Happy new year to you too! Indeed, I noticed it! I am going on holidays tomorrow and will be back on the 23rd. I don't think I'll have time to have a look at the PR before I leave, but I will definitely do it as the first thing when I get back!

MasaHirano commented 9 months ago

Have a nice vacation Gaël :)

gaelmarhic commented 9 months ago

Thank you so much :)