I am trying to create a project with teh version as 0.1.1 but gradle build is failing
It is always forcing me to use 2 digit versions like 0.1 or 0.2
How to get rid of this?
FAILURE: Build failed with an exception.
Where:
Build file '/xypath/build.gradle' line: 14
What went wrong:
Could not compile build file '/xypath/build.gradle'.
startup failed:
build file '/xypath/build.gradle': 14: unexpected token: 2 # line 14, column 15.
version = 0.1.2
^
1 error
My build.gradle looks like this
// Apply the java plugin to add support for Java
apply plugin: 'java'
version = 0.1.2
// In this section you declare where to find the dependencies of your project
repositories {
mavenLocal()
mavenCentral()
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile 'com.google.apis:google-api-services-drive:v2-rev157-1.19.1'
compile "org.apache.tika:tika-parsers:1.7"
compile 'org.springframework.amqp:spring-rabbit:1.4.3.RELEASE'
compile 'com.force.api:force-wsc:28.0.0'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'org.json:json:20131018'
compile 'net.oauth.core:oauth:20090617'
compile 'net.oauth.core:oauth-httpclient4:20090617'
compile 'net.oauth.core:oauth-consumer:20090617'
}
Gradle is just Groovy; 0.1.2 isn't a valid thing in Groovy. Try "0.1.2" instead.
After checking the available versions on gradle i can see that the oldest build version is 0.7, maybe you meant 1.2 not 0.1.2?
Related
In my Gradle project, I can declare a dependencies block with implementation entries, no problem. When I try to declare something like this, however, I get an error:
allprojects {
dependencies {
implementation("...")
}
}
The error I get:
Could not find method implementation() for arguments [org.mockito:mockito-core:2.25.0]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I wasn't able to reproduce this with a Java project, so it might have something to do with the Kotlin project. I'm new to Gradle, so I might just be doing something silly? Here's my environment info:
$ gradle --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_112 (Oracle Corporation 25.112-b15)
OS: Windows 10 10.0 amd64
Minimal reproduction
I can reproduce the issue with a minimal project.
build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
// This works.
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
// Causes an error. Using a random dependency to reproduce the issue.
allprojects {
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
settings.gradle:
rootProject.name = 'demo'
// Removing this line causes the error to go away, but means the module is missing.
include 'submodule'
submodule/build.gradle
// Empty file. I've tried adding various plugins (java / kotlin) to no avail.
The issue in your build.gradle is you are trying to use a build dependency configuration, in this case implementation without specifying the java plugin. The gradle docs says;
The Java plugin adds a number of dependency configurations to your
project, as shown below. Tasks such as compileJava and test then use
one or more of those configurations to get the corresponding files and
use them, for example by placing them on a compilation or runtime
classpath.
One way to fix this is to include java plugin as below (I have tested on 5.2.1 and it worked fine);
allprojects {
apply plugin: 'java'
dependencies {
implementation 'org.mockito:mockito-core:2.25.0'
}
}
The relationship of build configuration to the java plugin has been comprehensively described on
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
and
https://docs.gradle.org/current/userguide/managing_dependency_configurations.html#managing_dependency_configurations
Also, make sure you don't duplicate this dependency (or any other which is declared in the root or for all projects) in subprojects.
The problem
When running gradle jar, I receive the following error message.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve javax.units:jsr108:0.01.
Required by:
project : > org.geotools:gt2-metadata:2.5-M1
project : > org.geotools:gt2-metadata:2.5-M1 > org.opengis:geoapi-nogenerics:2.1-M8
> Could not resolve javax.units:jsr108:0.01.
> Could not parse POM http://download.osgeo.org/webdav/geotools/javax/units/jsr108/0.01/jsr108-0.01.pom
> Invalid byte 2 of 3-byte UTF-8 sequence.
I have tested this with Gradle 4.1 (currently latest) and Gradle 3.2.1, which gave the same error.
Indeed, looking at the POM file at the URL in the error, it can be seen that the encoding of that file is Windows-1252, not UTF-8. Why the error occurs is clear, but how can I address it? I cannot control the character encoding of the POM file. How do I tell Gradle about the non-UTF-8 encoding?
Reproducing this problem
Here is a minimal project to reproduce the error with.
build.gradle
apply plugin: 'java'
repositories {
maven {
url 'http://download.osgeo.org/webdav/geotools'
}
}
dependencies {
// https://mvnrepository.com/artifact/org.geotools/gt2-metadata
compile group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1'
}
src/main/java/HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Miscellaneous information
$ gradle -v
------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------
Build time: 2017-08-07 14:38:48 UTC
Revision: 941559e020f6c357ebb08d5c67acdb858a3defc2
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_141 (Oracle Corporation 25.141-b15)
OS: Linux 4.11.0-2-amd64 amd64
$ java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-8u141-b15-3-b15)
OpenJDK 64-Bit Server VM (build 25.141-b15, mixed mode)
Another possibility would be to download the JAR manually and configure the project to run with that reference. It seems that the error is part of the downloading process, and if you circumvent that process, the source will compile and run.
There is a download link on mvnrepository.com.
You can install the JAR into the Maven local repository
/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
You can find this path by not having the dependency, running gradle jar and looking at the error message. In the below, the second line starting with file: has the path you want to install the JAR.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.geotools:gt2-metadata:2.5-M1.
Searched in the following locations:
file:/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.pom
file:/home/you/.m2/repository/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
https://repo1.maven.org/maven2/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.pom
https://repo1.maven.org/maven2/org/geotools/gt2-metadata/2.5-M1/gt2-metadata-2.5-M1.jar
Required by:
project :
Here is my build.gradle file:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.geotools/gt2-metadata
compile group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1'
}
Im sorry to say I don't think there is a way to do this, I've tried to modify the configuration on the gradle dependency but there doesn't seem to be a way to mix in encodings.
Gradle derives it's character encoding straight from the JVM, and there doesn't seem to be away to specify a dependency having a different encoding. The problem also with that dependency is that it explicitly states that the encoding is UTF-8 but then the file has been written in Windows-1252 ..
You can specify this on your
JAVA_OPTS=-Dfile.encoding=Windows-1252
And that should parse your .gradle file and dependencies in Windows-1252 ... Failing that you could try to use a version of the g2-Metadata library that doesn't depend on the jsr library.
If you know that your not going to use anything in the jsr library then define it like this :
compile (group: 'org.geotools', name: 'gt2-metadata', version: '2.5-M1') {
exclude module: "jsr108"
}
I'm trying to upgrade some Gradle projects from Kotlin 1.0.6 to its latest version (1.1.0). However, whenever it reaches the compileKotlin task it fails:
:kiwi-common-kotlin:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':kiwi-common-kotlin:compileKotlin'.
> Could not find Kotlin Compiler jar. Please specify compileKotlin.compilerJarFile
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The project itself is divided in a bunch of subprojects. To avoid dupes, we have a separate file with the Kotlin definitions and import it on the projects using it:
File: gradle/kotlin.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
compileKotlin {
kotlinOptions.jvmTarget = "1.6"
}
And we import it in the subprojects like this:
apply from: "$rootDir/gradle/kotlin.gradle"
Since we previously tried the early preview releases and it worked seamlessly, I changed the version a couple times to see in which version the plugin broke. It turns out it works up to 1.1-M03; beginning at 1.1-M04 it shows the exact same error as in the 1.1.0 release.
We're using Gradle 2.10 in the project. Can you help me figure out whether it is a problem in our configuration? or a known issue with the Kotlin plugin itself?
It turned out to be a bug with the Gradle plugin. As pointed out by hotkeys' comment, updating to v1.1.2 fixes it.
I am writing a very simple program that uses stanford-corenlp. I am building my jar using gradle. I have Java 1.8 and stanford-corenlp version 3.6.
While building, it generates this error
FAILURE: Build failed with an exception.
What went wrong: A problem occurred evaluating root project 'StanfordCoreNLPTest'.
java.lang.StackOverflowError (no error message)
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.153 secs
Dependency for core nlp is specified in my gradle build file as
dependencies {
compile 'edu.stanford.nlp:stanford-corenlp:3.6.0'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6', classifier: 'models'
}
I would very much appreciate any help.
This is a gradle build file with which I have successfully built Java applications with stanford corenlp:
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6.0'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6.0', classifier: 'models'
}
Note that:
CoreNLP 3.6.0 requires Java 8. So I put source and target compatibility to 1.8
According to the official instructions to build with maven, you need 2 include statements for stanford-corenlp and in one of them you put classifier models. The above gradle file does that.
Ceylon 1.3.1 has just been released, one of the new items is better integration with Java projects/libraries. Decided to take one of the samples for a spin (https://github.com/DiegoCoronel/ceylon-spring-boot) alongside the ceylon-gradle plugin (https://github.com/renatoathaydes/ceylon-gradle-plugin).
As far as I can tell, turning this project into a multi-project Gradle build is a matter of adding two files with the following configuration.
settings.gradle
include 'gateway'
include 'discovery'
include 'foo'
include 'bar'
include 'foobar'
build.gradle
plugins {
id 'com.athaydes.ceylon' version '1.3.0' apply false
}
subprojects { subprj ->
subprj.apply plugin: 'com.athaydes.ceylon'
repositories {
mavenCentral()
}
ceylon {
module = subprj.name
}
}
Unfortunately building any of the modules results in errors, such as
$ gradle :gateway:compileCeylon
:gateway:resolveCeylonDependencies
:gateway:createDependenciesPoms
:gateway:createMavenRepo
:gateway:generateOverridesFile
:gateway:createModuleDescriptors
:gateway:importJars
:gateway:compileCeylon
source/gateway/module.ceylon:3: error: Pre-resolving of module failed: Could not find module: antlr/2.7.7
import ceylon.interop.java "1.3.0";
^
ceylon compile: There was 1 error
:gateway:compileCeylon FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gateway:compileCeylon'.
> Ceylon process exited with code 1. See output for details.
This happens using Gradle 3.2
------------------------------------------------------------
Gradle 3.2
------------------------------------------------------------
Build time: 2016-11-14 12:32:59 UTC
Revision: 5d11ba7bc3d79aa2fbe7c30a022766f4532bbe0f
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_112 (Oracle Corporation 25.112-b16)
OS: Mac OS X 10.10.5 x86_64
Tried setting additional properties on the ceylon configuration as explained in the plugin's documentation, such as
ceylon {
flatClasspath = false
importJars = true
forceImports = true
}
However the error persists. Any pointers on what I may be missing would be greatly appreciated.
This is because ceylon gradle plugin does not support yet the new feature --fully-export-maven-dependencies ... I created the issue now ;), so to make your project work you probably need to change each subproject/.ceylon/config with these options:
[compiler]
source=source
resource=resource
[defaults]
encoding=UTF-8
overrides=build/overrides.xml
flatclasspath=true
fullyexportmavendependencies=false
It will disable the new ceylon feature and uses ceylon gradle plugin feature and the generated overrides.xml file