gradle-git-properties icon indicating copy to clipboard operation
gradle-git-properties copied to clipboard

generate git properties in android project

Open eriknyk opened this issue 2 years ago • 7 comments

I've added the plugin to my android project, and git.properties not being generated automatically, it only works running manually the task generateGitProperties.

I saw a comment in other similar closed issue and it says that the git properties generation depends of classes task, now I can see that seems android projects have not a classes task, just because I've tried

.\gradlew.bat classes -debug

Output

---
 * What went wrong:
2021-12-16T14:42:20.138-0500 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Task 'classes' not found in root project 'myapp-android'.

is there a workaround to make the git.properties auto generated for android projects? I know that android have assembleDebug and assembleRelease default main tasks

Best Regards.

eriknyk avatar Dec 16 '21 19:12 eriknyk

Something like project.tasks. assembleRelease.dependsOn('generateGitProperties') will make generateGitProperties to be executed before assembleRelease

tha2015 avatar Dec 16 '21 19:12 tha2015

Thanks @tha2015 but it doesn't work

eriknyk avatar Dec 16 '21 23:12 eriknyk

I'm not familiar with Android projects. But generally when you makes a task A depends on some task B, that will make executing A implicitly executing B before A. Have you ran gradle command with debug flag to see what happened?

tha2015 avatar Dec 17 '21 00:12 tha2015

well not sure. I just added

project.tasks.assembleRelease.dependsOn('generateGitProperties')

and I got:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\erik\Github\myapp-android\build.gradle' line: 171

* What went wrong:
A problem occurred evaluating root project 'myapp-android'.
> Could not get unknown property 'assembleRelease' for task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.

eriknyk avatar Dec 17 '21 00:12 eriknyk

How about this one? project.tasks.processResources.dependsOn('generateGitProperties')

tha2015 avatar Dec 17 '21 00:12 tha2015

same error: > Could not get unknown property 'processResources' for task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.

checking the tasks names from android studio I can see that processResources does not exist, but there is a: processDebugResources task however project.tasks.processDebugResources.dependsOn('generateGitProperties') throws same error

eriknyk avatar Dec 17 '21 00:12 eriknyk

@tha2015

I've tried:

tasks.whenTaskAdded { task ->
    if (task.name == 'assembleDebug')
        task.dependsOn 'generateGitProperties'
    if (task.name == 'assembleRelease')
        task.dependsOn 'generateGitProperties'
}

And I can see that it works, but I'm not sure if that is the best way to fix this.

eriknyk avatar Dec 17 '21 01:12 eriknyk