why is gradle not printing the properties file? - gradle

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.

Related

Gradle 7.2 Tar task baseName deprecated but replacement archiveBaseName is rejected

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}"

Kotlin Gradle using dependencies

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().

Project with path ':projectA' could not be found in root project 'gradle-tutorial'

I'm new to Gradle and am following this Gradle tutorial, and it gives the following example, which I copied/pasted in my ~/gradle-tutorial/build.gradle file
project(':projectA') {
task hello
}
task hello
println tasks.getByPath('hello').path
println tasks.getByPath(':hello').path
println tasks.getByPath('projectA:hello').path
println tasks.getByPath(':projectA:hello').path
When I run
$ gradle -q hello
I get
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/myuser/gradle-tutorial/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'gradle-tutorial'.
> Project with path ':projectA' could not be found in root project 'gradle-tutorial'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I did create a ~/gradle-tutorial/projectA/build.gradle file, but still got the same error.
What am I missing?
Note I did find Project with path ':mypath' could not be found in root project 'myproject' but can't figure how to make that answer work for my simple one-file/one-directory case.
This error indicates that your settings.gradle file is missing or invalid. Inside it, you need to put a reference to the directories of the subprojects that you want to include in your build, like so:
include 'projectA'
For the build.gradle file inside your projectA subdirectory, you don't need to have any content since your root build.gradle file is already adding tasks specifically for the subproject by including the project(':projectA'){ } block. If you'd like to move the contents of that block to your subproject's build.gradle, the functionality would be equivalent.

libgdx project generation gradle error

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/' }

-a option in gradle

The following is from the gradle docs
The Task Tree context menu provides the following options:
Execute ignoring dependencies. This does not require dependent
projects to be rebuilt (same as the -a option).
It's not clear what is the -a option? I tried to execute gradle hl -a for the following build script:
task helloapi {
description = "Hello api"
}
task hl (dependsOn: 'helloapi'){
println "Hl"
description = "Hl"
}
helloapi << {
println "Hello api"
}
But I got
Hl
:api:helloapi
Hello api
:api:hl
I thought the only way to exclude tasks depending on the target task is to use -x option. BTW, when I tryied to ran it in gradle --gui I got the following error:
Executing command: "api:hl-a"
Hl
FAILURE: Build failed with an exception.
* What went wrong:
Project 'api' not found in project ':api'.
* 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: 6.751 secs
Is it a bug?
-a option ignores project dependencies - not task dependencies. Imagine that there's a complicated multimodule project. There was a change only in a single module (a task was changed) and You'd like to check if this task works well, when -a option is specified other module will not be rebuilt, just the changed one.

Resources