I'm trying to include org.apache.commons.net.* libraries in Kotlin using Gradle and command line.
In the dependencies in my build.gradle.kts file I wrote:
compile 'commons-net:commons-net:3.6' as it's said in the apache documentation but it gives me a weird errors as:
> Configure project :
e: D:\core\Confidential\Learn\Kotlin\build.gradle.kts:30:13: Too many characters
in a character literal ''commons-net:commons-net:3.6''
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\core\Confidential\Learn\Kotlin\build.gradle.kts' line: 30
* What went wrong:
Script compilation error:
Line 30: compile('commons-net:commons-net:3.6')
^ Too many characters in a character literal ''commons-ne
t:commons-net:3.6''
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
(I also tried with compile 'commons-net:commons-net:3.6' and compile group: 'commons-net', name: 'commons-net', version: '3.6').
I'm totally new with Kotlin and I'm trying to familiarize myself with it before starting Android development on IDEA.
Thanks.
Just like in Java, ' is for character literals, and " is for String literals.
You want "commons-net:commons-net:3.6".
And compile() is deprecated. Use implementation().
Related
I have started using Gradle 7.2 to build a project that produces a compressed Tar archive. Gradle is issuing a deprecation warning that baseName is deprecated and should be replaced with archiveBaseName. But it rejects archiveBaseName.
A very much simplified example using a trivial Gradle build script, with their associated execution outputs are given below. I did run 'gradle --stop' to ensure a prior version's daemon wasn't actually executing; a GRADLE_HOME environment variable is pointing to the correct Gradle folder (not sure it's needed, but it is set.)
I tried using "archiveBaseName" both without and with "=" ("archiveBaseName 'Test'" and "archiveBaseName='Test'").
The docs seem to suggest archiveBaseName should already be available, so I don't think it's just a heads up of things to come.
Thank you!
Gradle file:
task dist(type: Tar) {
baseName 'Test'
into ('.') { from('.') }
}
Execution:
gradle build --warning-mode=all
c:\jdev\newpaas\xxx>gradle build --warning-mode all
> Configure project :
The AbstractArchiveTask.baseName property has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the archiveBaseName property instead. See https://docs.gradle.org/7.2/dsl/org.gradle.api.tasks.bundling.AbstractArchiveTask.html#org.gradle.api.tasks.bundling.AbstractArchiveTask:baseName for more details.
at build_2qa2gx0itzunotwyc4ndf9v86$_run_closure1.doCall(C:\jdev\newpaas\xxx\build.gradle:2)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
> Task :buildEnvironment
------------------------------------------------------------
Root project 'TestProject'
------------------------------------------------------------
classpath
No dependencies
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 983ms
1 actionable task: 1 executed
Gradle file:
task dist(type: Tar) {
archiveBaseName 'Test'
into ('.') { from('.') }
}
Execution:
c:\jdev\newpaas\xxx>gradle build --warning-mode all
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\jdev\newpaas\xxx\build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'TestProject'.
> Could not find method archiveBaseName() for arguments [Test] on task ':dist' of type org.gradle.api.tasks.bundling.Tar.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Gradle file:
task dist(type: Tar) {
archiveBaseName='Test'
into ('.') { from('.') }
}
Execution:
c:\jdev\newpaas\xxx>gradle dist
> Task :dist FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':dist' (type 'Tar').
- Type 'org.gradle.api.tasks.bundling.Tar' property 'archiveFile' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'archiveFile'.
2. Mark property 'archiveFile' as optional.
Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#value_not_set for more details about this problem.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
I stumbled across this syntax and it seems to be working for me:
archiveFileName = "${archiveBaseName}-${archiveVersion}.${archiveExtension}"
how do I add the javafx dependencies through gradle?
thufir#dur:~/NetBeansProjects/helloWorldJavaFX$
thufir#dur:~/NetBeansProjects/helloWorldJavaFX$ gradle clean
> Configure project :
e: /home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts:13:7: Unresolved reference: openjfx
FAILURE: Build failed with an exception.
* Where:
Build file '/home/thufir/NetBeansProjects/helloWorldJavaFX/build.gradle.kts' line: 13
* What went wrong:
Script compilation error:
Line 13: org.openjfx.javafxplugin
^ Unresolved reference: openjfx
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
thufir#dur:~/NetBeansProjects/helloWorldJavaFX$
the manual says:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
my build file has:
plugins {
// Apply the java plugin to add support for Java
java
org.openjfx.javafxplugin
// Apply the application plugin to add support for building an application
application
}
which is generating the above error.
in the plugins-section you have to put
id("org.openjfx.javafxplugin") version "0.0.8"
instead of just org.openjfx.javafxplugin.
After that you can put a javafx-section like
javafx {
modules("javafx.controls", "javafx.fxml")
}
somewhere (I prefere to put it next to the dependency-section). Here you can put in any module you need.
For further configuration posibilities have a look JavaFX Gradle Plugin.
Based on references below:
https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-dependency-management/
I believe I can specify multiple dependencies under a dependency configuration like below:
However, when I try to run gradle build, I see the following errors.
Is this not the right way to provide multiple dependencies in a gradle file?
D:\TestGradle>gradle build
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\TestGradle\build-ProblemTemplate.gradle' line: 116
* What went wrong:
Could not compile build file 'D:\TestGradle\build-ProblemTemplate.gradle'.
> startup failed:
build file 'D:\TestGradle\build-ProblemTemplate.gradle': 116: expecting ')', found ',' # line 116, column 68.
toolVersions.mockitoVersion}'],
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
D:\TestGradle>
Also tried removing the [] in the testCompile configuration as mentioned in answer from Jakub Wójcik below. But still get the same error.
Update
Surprisingly, removing the line break after dependency configuration name worked for me.
It worked fine with or with out [] brackets. Still don't know why this matters, but updating the thread with my findings so far.
You can try specifying the dependencies with the configuration for each one of them. I think this is most common and used way.
dependencies {
compile 'dep1'
compile 'dep2'
}
or if you really want to just pass in a comma-separated args to compile closure.
dependencies {
compile (
'dep1',
'dep2'
)
}
PS. When using $variables you need to use the GString " (double quotes).
PPS. You can pass a vararg or an array to the configuration it doesn't really matter.
For the new lines
Gradle uses groovy for its scripts and this is not a bug its intentional actually, because () or {} may be interpreted as a separate block for the compiler. Refer to Context-sensitive_grammar
Its all to Groovy parser at the end of the day :)
Try removing the [] brackets, when having multiple dependencies for a testCompile clause. Also, note that you have an extra " in the line 118.
I am trying to execute simple print statements from in gradle/groovy but I get error
extProgram = new Properties()
extProgram.load(new FileInputStream("src/main/resources/version.txt"))
ext.appVersion=extProgram['version']
println ext.appVersion
This is the error I get
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "extProgram" on "root project 'appController'", value: "{}".
2.0.193
[buildinfo] Not using buildInfo properties file for this build.
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/Documents/codebase/app-controller/build.gradle' line: 54
* What went wrong:
A problem occurred evaluating root project 'appConroller'.
> Could not find method $() for arguments [build_5vi6ltfrgdviipcvtfu5rthgs1$_run_closure3_closure22_closure23#411109d] on root project 'appController'.
* 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: 9.972 secs
This is because extProgram is assumed to be a property of the project.
Try this instead:
def extProgram = new Properties()
...
This defines extProgram as a local variable.
I'm trying to generate a libgdx project but I'm getting the following error related to gradle.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\libgdx\gametest\build.gradle' line: 5
* What went wrong:
Could not compile build file 'C:\libgdx\gametest\build.gradle'.
> startup failed:
build file 'C:\libgdx\gametest\build.gradle': 5: unexpected token: } # line 5, column 5.
}
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Is there any way to fix this? Thanks!
This is really simple. Open the grade file. Change line 5 from
maven { https://oss.sonatype.org/content/repositories/snapshots/ }
to:
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }