Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commons: incorrect MavenPublication configuration #150

Closed
6 tasks done
tom93 opened this issue Mar 26, 2024 · 12 comments · Fixed by FossifyOrg/Commons#46
Closed
6 tasks done

Commons: incorrect MavenPublication configuration #150

tom93 opened this issue Mar 26, 2024 · 12 comments · Fixed by FossifyOrg/Commons#46
Labels
bug Something is not working

Comments

@tom93
Copy link

tom93 commented Mar 26, 2024

Checklist

  • I can reproduce the bug with the latest versions.
  • I made sure that there are no existing issues - open or closed - to which I could contribute my information.
  • I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
  • I have read the FAQs inside the app (Menu -> About -> FAQs), in the README and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report may get dismissed otherwise.
  • This issue contains only one bug.

Affected Android/Custom ROM version

N/A

Affected device model

N/A

How did you install the apps?

None

Which apps are affected?

No response

Steps to reproduce the bug

When I try to build one of the apps against a local version of Commons (using Maven's local repository) I run into errors. I think it's due to an issue with the configuration of the MavenPublication task, but maybe I'm just doing something wrong -- how do you normally build the apps against a locally-modified version of Commons?

Here are the steps I've been using:

  1. In Commons, edit gradle/libs.versions.toml and change app-version-versionName to something unique (e.g. "1.0.0-local").
  2. In Commons, run ./gradlew publishToMavenLocal
  3. In the app, edit gradle/libs.versions.toml and change the commons = "..." line to the same version. Also edit settings.gradle.kts and insert mavenLocal() at the top of the dependencyResolutionManagement section.
  4. In the app, build using ./gradlew assembleDebug

Expected behavior

It should succeed.

Actual behavior

It fails with:

> Task :app:dataBindingMergeDependencyArtifactsCoreDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dataBindingMergeDependencyArtifactsCoreDebug'.
> Could not resolve all files for configuration ':app:coreDebugCompileClasspath'.
   > Could not find org.fossify:commons:1.0.0-local.
     Required by:
         project :app

If I add --debug then I get:

[DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver] Attempting to resolve component for org.fossify:commons:1.0.0-local using repositories [MavenLocal, Google, MavenRepo, maven]
[DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading file:/home/user/.m2/repository/org/fossify/commons/1.0.0-local/commons-1.0.0-local.pom
[DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver] No meta-data file or artifact found for module 'org.fossify:commons:1.0.0-local' in repository 'MavenLocal'.
[DEBUG] [org.gradle.api.internal.artifacts.ivyservice.modulecache.PersistentModuleMetadataCache] Recording absence of module descriptor in cache: org.fossify:commons:1.0.0-local [changing = false]
[DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'org.fossify:commons:1.0.0-local' in resolver cache 'Google'
[DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'org.fossify:commons:1.0.0-local' in resolver cache 'MavenRepo'
[DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository] Detected non-existence of module 'org.fossify:commons:1.0.0-local' in resolver cache 'maven'
[DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading https://dl.google.com/dl/android/maven2/org/fossify/commons/1.0.0-local/commons-1.0.0-local.pom
[DEBUG] [org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor] Constructing external resource: https://dl.google.com/dl/android/maven2/org/fossify/commons/1.0.0-local/commons-1.0.0-local.pom
[DEBUG] [org.gradle.cache.internal.DefaultCacheCoordinator] Creating new cache for metadata-2.106/resource-at-url, path /home/user/.gradle/caches/modules-2/metadata-2.106/resource-at-url.bin, access org.gradle.cache.internal.DefaultCacheCoordinator@571e51d5
[DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Opening cache resource-at-url.bin (/home/user/.gradle/caches/modules-2/metadata-2.106/resource-at-url.bin)
[DEBUG] [org.gradle.internal.resource.transport.http.HttpResourceAccessor] Constructing external resource: https://dl.google.com/dl/android/maven2/org/fossify/commons/1.0.0-local/commons-1.0.0-local.pom
[DEBUG] [org.gradle.internal.resource.transport.http.HttpClientHelper] Performing HTTP GET: https://dl.google.com/dl/android/maven2/org/fossify/commons/1.0.0-local/commons-1.0.0-local.pom

Screenshots/Screen recordings

No response

Additional information

When I look in ~/.m2/repository, I the .pom file is actually in ~/.m2/repository/org/fossify/commons/release/1.0.0-local/release-1.0.0-local.pom and has the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!-- ...  -->
  <!-- do_not_remove: published-with-gradle-metadata -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.fossify.commons</groupId>
  <artifactId>release</artifactId>
  <version>1.0.0-local</version>
  <packaging>aar</packaging>
  <dependencies>
    ...

For comparison, https://jitpack.io/org/fossify/commons/b34aef8104/commons-b34aef8104.pom has the following contents (note that different groupId and artifactId):

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
  <groupId>org.fossify</groupId>
  <artifactId>commons</artifactId>
  <version>b34aef8104</version>
  <packaging>aar</packaging>
  <dependencies>
    ...

This makes me think that the Maven configuration is incorrect. The following patch fixes the problem for me (but I have no idea if it will cause problems with jitpack):

diff --git a/commons/build.gradle.kts b/commons/build.gradle.kts
--- a/commons/build.gradle.kts
+++ b/commons/build.gradle.kts
@@ -59,13 +59,13 @@
     sourceSets {
         getByName("main").java.srcDirs("src/main/kotlin")
     }
-    namespace = libs.versions.app.version.groupId.get()
+    namespace = "org.fossify.commons"
 }
 
 publishing.publications {
     create<MavenPublication>("release") {
         groupId = libs.versions.app.version.groupId.get()
-        artifactId = name
+        artifactId = libs.versions.app.version.artifactId.get()
         version = libs.versions.app.version.versionName.get()
         afterEvaluate {
             from(components["release"])
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -51,7 +51,8 @@
 app-build-javaVersion = "VERSION_17"
 app-build-kotlinJVMTarget = "17"
 #versioning
-app-version-groupId = "org.fossify.commons"
+app-version-groupId = "org.fossify"
+app-version-artifactId = "commons"
 app-version-appId = "org.fossify.commons.samples"
 app-version-versionCode = "1"
 app-version-versionName = "1.0.0"

I had to change how the namespace is set in commons/build.gradle.kts because it is no longer equal to the groupId. I'm not sure what the best practice is with respect to hard-coding (like I did for the namespace) or using a string from gradle/libs.versions.toml (like in MavenPublication); personally I think gradle/libs.versions.toml somewhat overkill and not really the right place for these non-dependency constants.

@tom93 tom93 added bug Something is not working needs triage Issue is not yet ready for PR authors to take up labels Mar 26, 2024
@naveensingh
Copy link
Member

@tom93 check settings.gradle.kts in the the gallery.

@tom93
Copy link
Author

tom93 commented Mar 26, 2024

Thanks. I tried it on File-Manager but got some errors (e.g. in ChangeViewTypeDialog.kt, useForThisFolderDivider had type DividerBinding instead of View), sounds very similar to the binding issues you ran into in SimpleMobileTools/Simple-Gallery#2967. I don't have a clue why, do you have any insights? (Since the Maven local repository works, my take is that it's not worth changing the code to make includeBuild() work unless includeBuild() is uncovering an actual bug.)

And is it okay if I still create a PR with my patch from above? The existing Maven configuration seem plain wrong.

@naveensingh
Copy link
Member

got some errors (e.g. in ChangeViewTypeDialog.kt, useForThisFolderDivider had type DividerBinding instead of View), sounds very similar to the binding issues you ran into in SimpleMobileTools/Simple-Gallery#2967. I don't have a clue why, do you have any insights?

Yep, it's the same issue. I never investigated it, it probably has something to do with how bindings are generated.

is it okay if I still create a PR with my patch from above?

Sure but please do test the Jitpack build once, you can trigger a build at https://jitpack.io/#org.fossify/commons or https://jitpack.io/#tom93/commons in your case.

tom93 added a commit to tom93/FossifyOrg-Commons that referenced this issue Apr 4, 2024
The configuration was incorrect. The JitPack build still worked, but
publishing to the Maven local repository using
`./gradlew publishToMavenLocal` was broken (incorrect paths and
metadata), and composite builds didn't get automatic dependency
substitution: building other apps against a local version of Commons
using `./gradlew --include-build=../Commons ...` didn't work, and
using `includeBuild("../Commons")` in <app>/settings.gradle.kts only
worked with a manual substitution directive[1].

Also move project identity values out of gradle/libs.versions.toml.

Detailed changes:

- Fix the Maven groupId (it should be "org.fossify", not
  "org.fossify.commons").

- Set the Gradle project group. This allows automatic dependency
  substitution in composite builds (`--include-build=../Commons`).
  Also set the Gradle project version for consistency.

- Use defaults for MavenPublication. (It's no longer necessary to
  explicitly set the Maven groupId/artifactId/version because they
  default to the Gradle project group/name/version. This also fixes
  the artifactId, which was previously "release" but should be
  "commons".)

- Avoid using libs.versions.toml for project identity. (That file is
  normally used for dependencies. Using it to set the project's own
  name and version is unusual. Also, it's confusing to have the
  "samples" project's appId and versionCode mixed together with the
  library things.)

- Move android.namespace declaration up (it's more logical and matches
  the official examples).

- Tweak the include() call in settings.gradle.kts (reorder so that
  "commons" is first because it's more important than "samples", and
  make colons consistent).

Fixes FossifyOrg/General-Discussion#150.

[1] https://github.com/FossifyOrg/Gallery/blob/692a5d08b30e7d4d374f53d7371781d05b482dc9/settings.gradle.kts#L26
@tom93
Copy link
Author

tom93 commented Apr 4, 2024

@naveensingh I created a PR (FossifyOrg/Commons#46) with an improved version of the patch from above that also fixes composite builds (and moves the values out of gradle/libs.versions.toml). I'm not sure how to trigger the JitPack build (it asks me to log in), can you please check for me? The commit is f0d9cd9f6f.

Aside: I found and wrote a patch for a serious issue in the Messages app relating to deletion, please give that priority over my other PRs!

@naveensingh naveensingh removed the needs triage Issue is not yet ready for PR authors to take up label May 1, 2024
@naveensingh
Copy link
Member

@tom93 It works™

@tom93
Copy link
Author

tom93 commented May 1, 2024

Yay, thanks!

@sauravpradhan
Copy link

sauravpradhan commented Nov 27, 2024

Just here for some clarity @tom93 . I am trying to build common separately as offline library.
Changes made to build.kts file for taking the :commons-aar from app/lib, however I get a lot of errors for resources and themes.
Were you successful in building it offline. Are there anything else we need to include. I am trying on calculator as of now.

@naveensingh
Copy link
Member

@sauravpradhan

Just add the following to Calculator's settings.gradle.kts then sync and rebuild:

includeBuild("path/to/the/cloned/Commons/")

If both Commons and Calculator are in the same directory, you can just do:

includeBuild("../Commons")

@sauravpradhan
Copy link

Will try this and get back.

@sauravpradhan
Copy link

sauravpradhan commented Nov 28, 2024

Getting same error as including aar :
image

Is there any more dependency then commons.aar ? I tried both ways building as a common module and then including aar. Both local build fails.

@tom93
Copy link
Author

tom93 commented Nov 28, 2024 via email

@sauravpradhan
Copy link

sauravpradhan commented Nov 28, 2024

@tom93 Thank you for the suggestion.
I tried a clean aar as it would be a best way to handle changes in multiple projects.
I managed to solve it by importing same version of gradle implementation on base app gradle:
-implementation("androidx.appcompat:appcompat:1.7.0")
-implementation("androidx.core:core-ktx:1.13.0")
-implementation("com.google.android.material:material:1.12.0")

These were throwing errors and declaring own "corner_radius". This should solve all errors as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants