I am getting an error while trying to include sendgrid-java during the build of a grails project.
I've added a compile time dependency as described in the documentation:
compile 'com.sendgrid:sendgrid-java:2.1.0'
But when I try to build it, it fails to resolve the dependency. I can see it is trying to download this zip file from mavenCentral, but it does not exist:
http://repo1.maven.org/maven2/com/sendgrid/sendgrid-java/2.1.0/sendgrid-java-2.1.0.zip
If I browse to the parent directory I can see many similar files but no .zip file. How can I get it to resolve the dependencies without the expected zip file? Can you tell gradle to use just the .pom file instead? I'm stuck!
There is lots of useful stuff here in this parent folder, just not zip file and i just can't get gradle to use it:
http://repo1.maven.org/maven2/com/sendgrid/sendgrid-java/2.1.0/
You have put this in the plugins{} block instead of the dependencies{} of your BuildConfig.groovy.
plugins is for grails plugins, which are distributed as .zip files, hence the error message with the file not being found.
"Regular" maven/ivy dependencies are handled just by the dependencies block (like in Gradle if you will).
The way you have it in the dependencies section of buildConfig.groovy is correct. It is in the Maven Central repository. So if you just have mavenCentral() in your repositories section of buildConfig.groovy all should be well.
Related
I need to make dex file from my android project. First, i need to compile my classes to jar. But i need dependencies in jar. otherwise, i'll get about 300 errors because of unknown methods. I need Timber in jar. but i can't find it in the internet. I searched a lot, but no luck. This is the link to the source code in github.
https://github.com/JakeWharton/timber
How do i build a jar from this gradle project?
To add gradle library to your project, you need to add implementation "package-group:package-name:package-version" to your build.gradle.
For Timber, you would do implementation "com.jakewharton.timber:timber:4.7.1".
If you want to compile your project, with its dependencies into a jar, then you want to look up "fat jars". Gradle Shadowjar is a plugin that does this.
I'm new to the maven tool, below is what I have understood about plugins and dependency:
Plugin is a Jar file which executes the task, and dependency is a Jar which provides the class files to execute the task.
What is the difference in maven between dependency and plugin tags in pom xml?
When I define something in the dependency tag, nothing is downloaded to my target folder. Whereas the same thing defined in the plugin tag downloads it in the target folder. Why plugin unpacks the jar file?
Update:
Plugins were unpacked as it was defined in the goal of the plugin.
Plugins and dependencies are completely different things.
Plugins are used by Maven during the build. They form the different parts of the build.
Dependencies are artifacts that should be used by the Java program you create in your build.
So you e.g. need the Maven compiler plugin to compile the code, but add guava as a dependency if your application wants to use guava.
When i define something in dependency tag, nothing is downloaded to my
target folder.
Exactly, all dependencies are placed into $USER_HOME/.m2/repository. They can be used by other mvn projects.
Whereas same thing defined in plugin tag downloads it in target folder. Why > plugin unpacks the jar file?
Can you share your pom.xml? It may depend on your configuration.
I'm using gradle V4.10.2 and eclipse for building WAR files. I have some common JAR files for all the wars. I need them to use only during compile time and need to exclude them while building into WAR file. Also I don't want to exclude all the JARs file.
I've put all the JARs in libs folder. In build.gradle, I have specified only the JARs to be included. Since the exclude list is bigger then include list of JARs I'm not using exclude
war {
rootSpec.include("**/test.jar")
}
The above results the WAR file without META-INF folder. Hence, webapp is not started. I have tried adding the libs as reference lib in eclipse but that results in compilation error.
Execution failed for task ':compileJava'.
Compilation failed; see the compiler error output for details
So I have to include all the JARs in libs folder and then need to use only required JARs in the WAR built. How to include only specific JARs into build?
I strongly recommend reading about building Java projects with Gradle and in particular the part about web applications
In short you should add the JARs needed for compilation only to the compileOnly configuration and the JARs needed for compilation and at runtime in the implementation configuration.
Gradle will then use all of them for compilation and only include the ones in implementation when packaging the WAR.
While you can do that by selecting them from your libs folder, I strongly recommend moving to libraries and its metadata sourced from a repository, private or public, so that the dependency management is done for you.
I am running a Spring Boot application through a gradle build and I observe that the dependency jars which are downloaded are kept in a subfolder inside the gradle caches folder, which has a different name.
For example, the gradle dependencies are downloaded in:
/root/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-gradle-plugin/2.0.5.RELEASE/2c7ddace2abd741a76720a29365d2dcd7633ef77/spring-boot-gradle-plugin-2.0.5.RELEASE.jar
However, I don't understand why the hash key (seems like one) is generated as a subfolder and the jar is inside the subfolder.
As a result of this, the dependency is not being found when I try to load it later during gradle build from a local repository. It shows an error message like could not resolve dependency.
Also why is the dependency being downloaded as org.springframework.boot and not org/springframework/boot? Since during picking up, it is expecting the dependency to be in a location like this.
Any help on how to resolve this will be appreciated. Thank you.
I'm building an Android app that has a dependency on a custom library, and Gradle is only willing to include my custom library when I use a project dependency, not when I use a files dependency to include the library's jar file. I'm building both my app and the library with the API levee 19 SDK.
failing dependencies section from build.gradle:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/MyLibrary.jar')
}
If I use the above dependencies section, none of the class in MyLibrary.jar are included in the build apk file, as verified by extracting its classes.dex and running dexdump. I have also verified that all of the classes are present in the jar file I'm using.
If I use the following dependencies section, then all of the classes in MyLibrary are included in the apk file:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile project(':MyLibrary')
}
I'm using Android Studio 0.4.0, Gradle 1.9, and I think the Gradle plugin 0.7.1.
What is going on here? I'd really like to build my app with the API level 18 sdk to test compatibility, but I can't get that working unless I'm able to just use the jar file for my library.
Okay, this was my fault. My library's build.gradle was configured to only include the source files in the jar output file. The following is incorrect Gradle code and will give you the same problems as I've had.
task jar(type: Jar) {
from android.sourceSets.main.java
}
This answer shows how to fix the jar file creation. It's ugly, but it seems to work.
Jar task does not include dependencies in the final jar artifact.
From Gradle documentation on jar task:
The jar task creates a JAR file containing the class files and
resources of the project.
It assumes that since you are building jar for your project, all dependencies will be provided during runtime. As opposed to war, where all dependencies are usually included in the final artifact.
If you need to create "fat jar", which will include the dependencies, then look into specific plugins, for example gradle-fatjar-plugin.
It's a little bit of a longshot, but if you're not using Android Studio 0.4.0 and you've just added the jar file, try cleaning your project and rebuilding from scratch. We've seen this bug: https://code.google.com/p/android/issues/detail?id=63366 where libraries don't get included without cleaning the project, though this bug refers to a dependency downloaded from Maven and not a local jar file (which may or may not be an important difference). This was fixed in Android Studio 0.4.0 (more specifically, in the Gradle plugin 0.7.0).