com.google.appengine:appengine:+ vs com.google.cloud.tools:appengine-gradle-plugin:+ - java

I am new to gradle concept. I'm doing gradle for app engine (I don't know maven or ant) and I gone through in [https://cloud.google.com/appengine/docs/standard/java/tools/gradle] but I can't able to understand the difference between the:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+'
}
}
and:
repositories {
jcenter()
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine:+'
}
I searched in the internet I can't able to understand? Can anyone explain this?

It may be confusing at the very beginning but is quite easy. With gradle you do manage the project but both gradle and the project that is managed can have their own dependencies. So, if you'd like e.g. use guava to compile your project files it will be:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:22.0'
}
but if you'd like to use guava in build.gradle file then the following piece of code is necessary:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.guava:guava:22.0'
}
}
So buildscript is used to configure build.gradle itself.
In the example provided buildscript block is used to configure dependency for plugin that is applied later on in build.gradle and the second block configures the dependencies for the project itself.

Related

How I can use MapMyIndia in kotlin?

I can't use MapMyIndia in kotlin, I need to know how I can install it.
Now in my code I got this:
Project level build.gradle
maven {
url 'https://maven.mapmyindia.com/repository/mapmyindia/'
}
App level dependency build.gradle
implementation 'com.mapmyindia.sdk:mapmyindia-android-sdk:6.8.2'
But when I want to use anything with MapMyIndia on my activity or xml I got none about it.
There is one more place where you should import the.
in settings.gradle Project Settings and
should look something like this
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://maven.mapmyindia.com/repository/mapmyindia/' }
}
}
rootProject.name = "This is Sparta"
include ':app'
That should do the trick.

Understanding buildscript

How to understand following build.gradle script:
buildscript
{
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
According to my understanding repositories{} defines dependencies{} locations.
I see that dependencies wrapped inside of buildscript defines tomcat plugin. But what is idea to do so in such strange way?
Whole script:
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'eclipse-wtp'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.1'
}
}
dependencies {
def tomcatVersion = '8.0.46'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
api 'org.apache.commons:commons-math3:3.6.1'
}
tomcat {
httpPort = 8080
enableSSL = true
contextPath = '/library-spring'
}
Nowadays almost all plugins for Gradle are published to the Gradle Plugin Portal, so Gradle knows how to resolve them and you can simply use the plugins block to define them in your build script:
plugins {
id 'com.bmuschko.tomcat' version '2.5'
}
In earlier days of Gradle, plugins could only be distributed in the same way as any other library, e.g. using a public Maven repository like Maven Central or Bintray. This way they could be resolved in the same way as other libraries, using the dependencies block to define what to resolve and using the repositories block to define where to resolve.
The problem of using the regular repositories and dependencies blocks is, that those dependencies are loaded when the build script gets evaluated. But to evaluate the build script, the plugin libraries are required to be on the classpath.
For this reason, the buildscript block was introduced to load all the dependencies before evaluating the actual build script. This is also the reason why the buildscript block should always go first in a build script:
buildscript {
repositories {
// where to resolve dependencies of your build script
}
dependencies {
// what dependencies to resolve for your build script
}
}
repositories {
// where to resolve dependencies of your project code
}
dependencies {
// what dependencies to resolve for your project code
}

How does Android search for dependencies on GitHub?

i want to implement a dependency from GitHub in my android project but it gives me this error
Could not find com.github.RobertApikyan:SegmentedControl:1.2.0
I'm implementing this:
implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'
I think is the case because by build.gradle file doesn't search on GitHub for repos.
This is my build.gradle file:
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Workaround 1:
You can host a project release into mavenCentral using github, it is located at:
https://github.com/{user}/{repository}/packages?package_type=Maven
And in order to pull packages from it, add new repository in your build.gradle:
mavenCentral()
Wordaround 2:
You can host your project's any branch or version at jitpack.io
and the great thing is that you don't need to setup anything it'll build your packages in their server and notify you. Your project will be located at:
https://jitpack.io/#{user}/{repository}
And in order to pull packages from it, add new repository in your build.gradle:
maven { url 'https://jitpack.io' }

ERROR: Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8

I have problem with build project in android-studio from https://github.com/Samsung/microbit.
I imported repository by git, but while build gradle project from in android-studio I have error:
ERROR: Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71.
I am not sure how I can change version 1.2.72 to other version.
Edit:
Solution:
I added mavenCentral() to
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
google()
}
}
I think there is no need to use that as you can use kotlin-stdlib directly.
Try this:
In your app level build.gradle file, under dependencies section:
dependencies{
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.41"
}

Neokree Navigation drawer: Gradle DSL method not found: 'compile()'

I am trying to Set up a Navigation Drawer by Neokree https://github.com/neokree/MaterialNavigationDrawer on Android Studio with no success.
After adding this to my gradle -> build.gradle file
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
And then i get this Error Saying "Gradle project Sync Failed" and this below
Error:(27, 0) Gradle DSL method not found: 'compile()'
Possible causes: The project 'MaterialNavigationDrawer' may be using a version of Gradle that does not contain the method.
Gradle settings The build file may be missing a Gradle plugin.
Apply Gradle plugin.
This is my gradle folder -> Build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
I know am doing something wrong for sure, and I can't seem to figure it out.
There is a great library called MaterialDrawer. You can integrate this library in less than 5 minutes in your project (read its README.md and Wiki - a lot of informations is available there!).
Good luck!

Categories