How to skip testRuntime task in gradle? - gradle

In my eclipse, there are many projects that build with gradle. I want to skip the testRuntime task in gradle. Because It's too slow and makes me wait for long time whenever I change some code or give changes the projects. How can I avoid this? I want to apply every relevant projects.
UPDATE
This is the result of gradle task. Eclipse is executing background job and I check these jobs in the process tab and I can see this message like the followings.
Gradle Build on xxx project
Executing tasks : xxxx:TestRuntime
I think It takes time because of firewall. I want to skip this process. I guess, It can be done by eclipse or by gradle configuration.
My build.gradle file
buildscript {
repositories {
mavenLocal()
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/groups/openpms-public'
credentials {
username 'openpms'
password 'openpms0'
}
}
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/repositories/thirdparty'
credentials {
username 'developer'
password 'developer0'
}
}
maven { url 'http://70.121.224.52:8081/nexus/content/repositories/central/' }
jcenter{ url 'http://70.121.224.52:8081/nexus/content/repositories/jcenter/' }
}
dependencies {
classpath "org.akhikhl.gretty:gretty:$gretty_version"
}
}
repositories {
mavenLocal()
maven {
url 'http://70.121.244.11:8081/nexus/content/groups/openpms-public'
credentials {
username "$maven_username"
password "$maven_password"
}
}
maven { // for thridparty lib
url 'http://70.121.244.11:8081/nexus/content/repositories/thirdparty'
credentials {
username 'developer'
password 'developer0'
}
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
sourceCompatibility = 1.6
targetCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' // compileGroovy, compileTestGroovy
def spring_version = '4.0.6.RELEASE'
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'org.opensymphony.quartz', name: 'quartz', version: '1.6.1'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.4'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
gretty {
servletContainer = 'jetty8'
port = 8080
contextPath = '/agent.server'
}
UPDATE 2
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] tasks
[sts] -----------------------------------------------------
<org.gradle.api.plugins.quality.PmdExtension_Decorated#729eaf4b __dyn_obj__=org.gradle.api.internal.AsmBackedClassGenerator$MixInExtensibleDynamicObject#2fc49256 __mapping__=org.gradle.api.internal.ConventionAwareHelper#1263649a __consoleOutput__=false __ignoreFailures__=true __reportsDir__=true __ruleSetConfig__=false __ruleSetFiles__=true __ruleSets__=true __sourceSets__=true __targetJdk__=false __toolVersion__=true project=root project 'redca-agent' ruleSets=[basic] targetJdk=null ruleSetConfig=null ruleSetFiles=file collection consoleOutput=false toolVersion=4.3 sourceSets=[source set 'main'] ignoreFailures=true reportsDir=D:\workspace\redCAGit\redca-agent\build\reports\pmd>
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Application tasks
-----------------
bootRun - Run the project with support for auto-detecting main class and reloading static resources
installApp - Installs the project as a JVM application along with libs and OS specific scripts.
run - Runs this project as a JVM application
Build tasks
-----------
assemble - Assembles the outputs of this project.
bootRepackage - Repackage existing JAR and WAR archives so that they can be executed from the command line using 'java -jar'
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles classes 'main'.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles classes 'test'.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Distribution tasks
------------------
assembleDist - Assembles the main distributions
distTar - Bundles the project as a distribution.
distZip - Bundles the project as a distribution.
installDist - Installs the project as a distribution as-is.
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
components - Displays the components produced by root project 'redca-agent'. [incubating]
dependencies - Displays all dependencies declared in root project 'redca-agent'.
dependencyInsight - Displays the insight into a specific dependency in root project 'redca-agent'.
help - Displays a help message.
model - Displays the configuration model of root project 'redca-agent'. [incubating]
projects - Displays the sub-projects of root project 'redca-agent'.
properties - Displays the properties of root project 'redca-agent'.
tasks - Displays the tasks runnable from root project 'redca-agent' (some of the displayed tasks may belong to subprojects).
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
findbugsTest - Run FindBugs analysis for test classes
pmdTest - Run PMD analysis for test classes
Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 2.354 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 2 sec
[sts] -----------------------------------------------------
I want to know the way to skip working testRuntime.
Even if it is not task, my concern is not to waste time.
How can I avoid this?

I am a newbie in gradle and I am not goot at English. Please understand.
Anyway, I solved by myself. Eclipse gradle plugin, I am using, is trying to connect the repository on the internet that may be blocked by firewall. So I can't solve this. There are many workplaces including the place where is offline.
I could skip this giving the parameter to Program Arguments like the followings. you can add this property in eclipse preference > Gradle > Arguments.
--offline

Related

Can I call the Gradle properties task on all projects at once in a multi-project build?

I would like to view the properties of a Gradle project, to manually ensure the values look right.
When I call the properties task from the root of a multi-project build, it lists the properties of the root project:
$ gradle -q properties
------------------------------------------------------------
Root project
------------------------------------------------------------
allprojects: [root project 'myapp', project ':api', project ':model', project ':ui']
ant: org.gradle.api.internal.project.DefaultAntBuilder#12345
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory#12345
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated#12345
asDynamicObject: DynamicObject for root project 'myapp'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope#12345
[...]
I can also request the properties for each individual subproject:
$ gradle -q :api:properties
------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------
allprojects: [project ':api']
ant: org.gradle.api.internal.project.DefaultAntBuilder#12345
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory#12345
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated#12345
asDynamicObject: DynamicObject for project ':api'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope#12345
[...]
However, what I really want to do is list the properties for a given project and all its subprojects at once.
I'm a bit surprised that calling the task at the root level only gives the root level properties. This seems to contradict the Gradle documentation about executing tasks by name in a multi-project build:
The command gradle test will execute the test task in any subprojects, relative to the current working directory, that have that task. If you run the command from the root project directory, you’ll run test in api, shared, services:shared and services:webservice. If you run the command from the services project directory, you’ll only execute the task in services:shared and services:webservice.
The basic rule behind Gradle’s behavior is: execute all tasks down the hierarchy which have this name. Only complain if there is no such task found in any of the subprojects traversed.
How do I list all properties for a project and its subprojects at once? And as a bonus, why isn't the properties task run at the root level also running for the sub-projects? I am using the currently latest version of Gradle (6.7.1).
Per this Gradle Forum response, the properties task is not running for subprojects since the impliesSubProjects property of the properties task is true in the property implementation:
The task is configured to ignore subproject tasks by the HelpTasksPlugin using an internal API
[…]
Then TaskNameResolver does not look at subprojects for the task if impliesSubProjects is true.
Experimentation shows that the impliesSubProjects property can be configured in the build file, allowing the task to be run for the parent project and all its children:
properties {
impliesSubProjects = false
}
Output
$ gradle -q properties
------------------------------------------------------------
Root project
------------------------------------------------------------
allprojects: [root project 'myapp', project ':api', project ':model', project ':ui']
ant: org.gradle.api.internal.project.DefaultAntBuilder#12345
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory#12345
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated#12345
asDynamicObject: DynamicObject for root project 'myapp'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope#12345
[...]
------------------------------------------------------------
Project :api - The shared API for the application
------------------------------------------------------------
allprojects: [project ':api']
ant: org.gradle.api.internal.project.DefaultAntBuilder#12345
antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory#12345
artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated#12345
asDynamicObject: DynamicObject for project ':api'
baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope#12345
[...]
------------------------------------------------------------
Project :model - Shared object model
------------------------------------------------------------
[...]
Note, however, that the impliesSubProjects property is defined in the internal API (org.gradle.api.internal.AbstractTask and is not part of the public Task API (see Avoid using internal Gradle APIs for more details on internal APIs). Therefore, as mentioned in the linked forum response, this is not intended to be used in builds:
keep in mind that it’s an internal implementation detail not intended to be used by builds and there are no guarantees it will keep working in future Gradle releases.
However, in the case of a one-off property comparison that's not a persistent part of the build, this sort of unintended usage is likely acceptable.
May be I understood your question incorrectly. If you want to list all properties including all subproject along with the root project, then you can create a build file as follows:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
allprojects {
repositories {
mavenCentral()
}
group = "com.nononsensecode"
version = "0.0.1"
}
plugins {
kotlin("jvm") version "1.4.20" apply false
base
}
configure(subprojects) {
apply {
plugin("org.jetbrains.kotlin.jvm")
}
configure<JavaPluginExtension> {
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
dependencies {
val implementation by configurations
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
}
task("listAllProperties") {
val subProjectPropertiesMap = mutableMapOf<String, Map.Entry<String, Any?>>()
subprojects.forEach { subProject ->
subProject.properties.forEach { property ->
subProjectPropertiesMap[subProject.name] = property
}
}
val allProperties = AllProperties(properties, subProjectPropertiesMap)
println(allProperties)
}
}
data class AllProperties(
val properties: Map<String, Any?>,
val subProjectProperties: MutableMap<String, Map.Entry<String, Any?>>
)
Then run the task gradlew listAllProperties. If you want, you can create a toString method to print all properties in a beautiful way.

Gradle tasks shown in intellij but can not be run

I have a multi module project with the following structure:
root_project
module1
module2
module3
I try to apply the java plug-in to all projects using the following code:
allprojects {
apply plugin: 'java'
group = 'com.mysoftware'
sourceCompatibility = 1.8
version = '1.3'
repositories {
mavenCentral()
}
}
Additionally I add the javafx plugin to module3. The java and javafx tasks are now shown in the intellij gradle view, but when trying to execute them, I get this error:
Task 'jfxJar' not found in root project 'module3'.
Furthermore, running the tasks task show me that neither the java tasks nor the javafx tasks are available, despite being shown in the gradle view in intellij.
I tried rebuilding and refreshing the whole project without success. I use the Use default gradle wrapper configuration.
The error message you got Task 'jfxJar' not found in root project 'module3' indicates that Gradle considers the subproject module3 as a Root project: this can happen if you created a settings.gradle file in the sub-project directory, which is not a valid setup (only one settings.gradle file can exist in a multiproject build, located in the root directory)

gradle: why there is no jar task for all sourceSets

Added sourceSet web, but there is no corresponding tasks for it:
apply plugin: 'java'
sourceSets {
web
}
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
webClasses - Assembles web classes.
I expected the following task
webJar
Gradle assemble and build: does not build web sourceSet.
there's not a jar task per sourceSet because in most projects this jar is not required. For example the java project comes with two sourceSets (main and test). A jar for the test sourceSet is not needed as you can run the tests without it.
If you need a jar for your additional sourceSet you can easily create one:
task myJar(type:Jar){
from sourceSets.mySourceSet.output
}

Gradle - Could not find or load main class src.main.java.Test

I have the following folder structure and want to play with gradle testing.
Before starting any tests I want to see what tasks are available.
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that
depend on it.
buildNeeded - Assembles and tests this project and all projects it depends
on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root
project 'GradleTesting'.
components - Displays the components produced by root project
'GradleTesting'. [incubating]
dependencies - Displays all dependencies declared in root project
'GradleTesting'.
dependencyInsight - Displays the insight into a specific dependency in root
project 'GradleTesting'.
help - Displays a help message.
model - Displays the configuration model of root project 'GradleTesting'.
[incubating]
projects - Displays the sub-projects of root project 'GradleTesting'.
properties - Displays the properties of root project 'GradleTesting'.
tasks - Displays the tasks runnable from root project 'GradleTesting'.
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
execute
So I know that there isn't any problect with gradle. Now I write this code in my build.gradle file.
apply plugin: 'java'
task execute(type: JavaExec) {
//This line throws me an exception.
main = "src.main.java.Test"
classpath = sourceSets.main.runtimeClasspath
}
And get this message.
$ gradle execute
:compileJava
:processResources UP-TO-DATE
:classes
:executeError: Could not find or load main class src.main.java.Test
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':execute'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe''
finished with non-zero exit value 1
Any ideas how to fix this error?
Thanks.
'src/main/java' is the file system path to the java files.
The package names start here.
In your case there is no package name, the fully-qualified class name is "Test" so, change your build.gradle to:
apply plugin: 'java'
task execute(type: JavaExec) {
main = 'Test'
classpath = sourceSets.main.runtimeClasspath
}

Gradle clean<customTask> not working

I have a custom task to do a Websphere EJBDeploy. I have defined the inputs and ouputs, and get successful incremental compilation, but I can't get the automatically generated clean task to work properly.
According to docs, for a custom task named "ejbDeploy" with a defined output, a cleanEjbDeploy task should be automatically generated.
Pattern: clean<TaskName>: Cleans the output files of a task.
So here's my custom task:
task ejbDeploy(dependsOn: 'jar'){
srcFile = file(jar.archivePath)
destDir = new File("build/ejbDeploy")
inputs.file srcFile
outputs.dir destDir
def cp = project.files(
project.sourceSets.main.output.classesDir,
project.sourceSets.main.resources,
project.configurations.runtime
).getAsPath()
doLast{
destDir.mkdirs()
exec{
executable = wasEjbDeploy
workingDir = destDir
args = [
jar.archivePath,
".",
jar.archiveName,
"-cp",
cp
]
}
}
}
Anyone have any ideas as to why the clean rule isn't working?
[Edit]
Here's the full (anonymized) file contents (this has changed since initial question post):
version = '1.0-SNAPSHOT'
group = 'com.company'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'name.benjaminAbbitt', name: 'WASEjbDeploy', version: '1.0-SNAPSHOT'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'base'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'javax.mail:mail:1.4.5'
compile 'log4j:log4j:1.2.16'
compile files(fileTree(dir: 'lib', includes: ['*.jar']) )
}
task ejbDeploy(type:name.benjaminAbbitt.WASEjbDeploy, dependsOn: 'jar'){
wasEjbDeployPath = wasEjbDeploy
}
Here's the relevant chunk of "$gradle tasks"
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend
on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles the test classes.
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
dependencies - Displays the dependencies of project ':project'.
help - Displays a help message
projects - Displays the sub-projects of project ':project'.
properties - Displays the properties of project ':project'.
tasks - Displays the tasks runnable from project ':project' (some of the
displayed tasks may belong to subprojects).
IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
eclipse - Generates all Eclipse files.
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Other tasks
-----------
ejbDeploy
Rules
-----
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belongin
g to a configuration.
Pattern: clean<TaskName>: Cleans the output files of a task.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.321 secs
The clean rule is provided by the base plugin. Since many other plugins (e.g. java) already apply the base plugin, you typically don't have to apply the base plugin yourself. But in case:
apply plugin: "base"

Resources