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

Usage documentation incorrect #80

Closed
ac87 opened this issue Sep 24, 2020 · 5 comments · Fixed by #81 or #89
Closed

Usage documentation incorrect #80

ac87 opened this issue Sep 24, 2020 · 5 comments · Fixed by #81 or #89
Labels
bug Something isn't working

Comments

@ac87
Copy link

ac87 commented Sep 24, 2020

@mateuszkwiecinski I could be wrong but I think there's issues with the readme

It says:

// in app/build.gradle
plugins {
  id "com.starter.easylauncher" version "${{version}}"
}

I believe this is wrong, this only works in the root build.gradle (in groovy at least)

then in app/build.gradle you need to add
apply plugin: 'com.starter.easylauncher'
which isn't documented but is in all your sample projects.

@issue-label-bot issue-label-bot bot added the bug Something isn't working label Sep 24, 2020
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.81. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@mateuszkwiecinski
Copy link
Member

mateuszkwiecinski commented Sep 26, 2020

Thanks for raising concern! So in general, the documentation properly references how the plugin should be applied, and it should take pleace where the com.android.application plugin is being registered.
I assume you got an error that it cannot find Android Gradle Plugin on Gradle Plugin Portal 🤔 In the project you provided I was able to get following message:

> Could not resolve all artifacts for configuration ':app:classpath'.
   > Could not find com.android.tools.build:gradle:4.0.1.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :app > com.starter.easylauncher:com.starter.easylauncher.gradle.plugin:3.3.0 > com.project.starter:easylauncher:3.3.0

That means your project buildscript didn't have any other repository than gradle plugin portal and the solution would be adding to your app/build.gradle

buildscript {
    repositories.google()
}
plugins {
    id "com.starter.easylauncher" version "3.3.0"
}

I'll mention that in a Readme. But basically that's a limitation of the new plugins block :/

And just to explain: it started to work after applying the plugin to your root projects's build.gradle because of the fact you apply AGP there to its buildsscript, so it could add the easylauncher plugin so it was on the buildscript classpath so at the end it could be applied with regular apply call.

Regarding the

but is in all your sample projects.

Sample projects here are a bit special. I had to do a bit of gradle magic to be able to apply the plugin in a compiled form. Such usage exceeds the new plugins api capabilities hence I had to use the reguler apply: call. Sorry for the confusion it caused :/

@ac87
Copy link
Author

ac87 commented Sep 28, 2020

Correct on the error I get if I try to include the plugin block in app/build.gradle

But if its in the root build.gradle and you don't include apply plugin: 'com.starter.easylauncher' it doesn't actually apply the plugin, so no icons get changed despite it being quite happy with you including the easylauncher { ... } block which is quite confusing.

@mateuszkwiecinski
Copy link
Member

You're right. It won't work when applied to a root project - there are no icons that can be processed. And as the plugin is registerd on the project classpath you will be able to use the easylauncher extension. I'm not sure I can use anything more here :/

However, I might have misled you with recommended way of applying the plugin in such case. I've rembered that having multiple builscripts in your project isn't considered a good practice. So instead of directly adding to your project

// app/build.gradle
buildscript {
    repositories.google()
}

there are 2 more conventional ways of solving the issue:

  1. According to the Gradle docs it can be achieved with apply false call:
// root project's build.gradle
buildscript {
    repositories.google()
}
plugins {
    id 'com.starter.easylauncher' version 'x.x.x' apply false
}
// app/build.gradle
plugins {
    id 'com.starter.easylauncher' // no need for version, the plugin has been already resolved
}
or 
apply plugin: 'com.starter.easylauncher'

so the plugin gets resolved in root project, where it has google repository available, but it is applied only to single app module - which is expected.

  1. Using legacy plugin configuration as menioned on Gradle Plugin Portal
// root project's build.gradle
buildscript {
  repositories.google()

  dependencies {
    classpath "com.project.starter:easylauncher:x.x.x"
  }
}
// app/build.gradle
plugins {
    id 'com.starter.easylauncher'
}
or
apply plugin: 'com.starter.easylauncher'

Here's an example application: afaucogney's repository

@ac87
Copy link
Author

ac87 commented Sep 29, 2020

@mateuszkwiecinski That makes more sense, I guess I've kind of found a half way between the legacy way and the new way by .

Instead of the

dependencies {
    classpath "com.project.starter:easylauncher:x.x.x"
  }

block I've added the plugins block to the root build.gradle file.

I didn't realise there was so many ways to do it. Great tip on the apply false bit though. Hadn't really thought that through but unlike you I've not been developing plugins so I won't beat myself up too much!

I could be wrong

I think its safe to say I was

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants