I created a minimal build.gradle file:
apply plugin: "java"
and put a minimal set of Java files in src/main/java.
When I run:
gradle dependencies
I see various tasks with no dependencies, such as:
compileOnly - Compile only dependencies for source set 'main'.
No dependencies
However, when I try to run one of them:
gradle compileOnly
I see:
Task 'compileOnly' not found in root project '21-java'.
So where is this task and how can I see it?
Related
Use Case
I am trying to generate a dependency tree containing all plugins and dependencies for all configurations, but org.sonarqube is not included in the tree. I am working with a basic, single-module project and am using Gradle v7.5.1.
Examples
Running the following command outputs most (but not all) dependencies and plugins.
gradlew dependencies > dependency-tree.txt
Specify SonarQube plugin within build.gradle
plugins {
id 'org.sonarqube' version '3.2.0'
}
Specify SonarQube plugin within settings.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.2.0"
}
}
apply plugin: "org.sonarqube" // set in build.gradle, not in settings.gradle
Results
Neither approach includes the org.sonarqube plugin in the dependency graph. Is there a way to get this plugin to show up in the generated dependency tree? If yes, what changes need to be made?
The dependencies task provides the projet dependencies in each configuration, this does not include the projet script classpath (plugins).
You have another similar task available, buildEnvironment (see BuildEnvironmentReportTask) which will list the project build script dependencies.
you could combine both tasks outputs if you need a aggredated report of all project/plugin dependencies
> Task :buildEnvironment
------------------------------------------------------------
Root project 'demo'
------------------------------------------------------------
classpath
\--- org.sonarqube:org.sonarqube.gradle.plugin:3.2.0
\--- org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.2.0
\--- org.sonarsource.scanner.api:sonar-scanner-api:2.16.1.361
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 452ms
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)
This is the dialog indicating the modules which are being deleted
but when I import a new project with build.gradle and I do not enable auto import now I have a dialog asking my if I would like to enable auto import, and the modules are no longer deleted automatically.
Here is the build.gradle file
/*------------------------------------------------------------------------------
Gradle latest file.
Build command:
./gradlew deploy
Create Javadocs at ./latest/docs/javadoc/index.html
./gradlew buildJavadocs
Other commands of interest:
./gradlew wrapper --gradle-version 4.7
./gradlew tasks
./gradlew properties
Manual search for dependencies in Gradle repository:
https://bintray.com/bintray/jcenter/io.appium%3Ajava-client
------------------------------------------------------------------------------*/
group 'com.my.group'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceSets {
main {
java {
srcDir 'src/'
}
}
}
sourceCompatibility = 1.8
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile 'junit:junit:4.12'
compile 'org.seleniumhq.selenium:selenium-java:3.11.0'
compile 'io.appium:java-client:6.1.0' // /compile 'io.appium:java-client:6.0.0-BETA5'
//compile 'io.appium:java-client:6.0.0-BETA5' // compile 'io.appium:java-client:6.1.0'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.google.guava:guava:24.1-jre'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
}
task copyToLib(type: Copy, dependsOn: build) {
String dst = "$rootDir/jar"
description "Copy library JAR dependencies to $dst"
from configurations.runtime
into "$dst"
}
task copyToOut(type: Copy, dependsOn: build) {
String dst = "$rootDir/out"
description "Copy library JAR output to $dst"
from jar
into "$dst"
}
task deploy {
dependsOn clean
dependsOn build
dependsOn copyToLib
dependsOn copyToOut
}
task buildJavadocs(type: Javadoc) {
exclude 'srcOld/**'
classpath += sourceSets.test.compileClasspath
source += sourceSets.main.allJava
}
edit
When Gradle deletes the modules, it also delete gradle.build and the gradle wrapper. I've already created a brand new project with the default Java template, and copied and pasted my code into it, but the problem persists.
In case of a Gradle projects IDE configures the project structure including the modules that are included in project according your the build.gradle script. E.g. if you have Create separate module per source set option enabled in IDE Gradle settings IDE creates separate module for each Grale source set. It does it when re-importing build.gradle file. If you have auto-import enabled in IDE Gradle configuration it does it automatically.
Given the limited information, I'll give you an ad-hoc fix, just add -----test as a sub-project directory to your root projects settings.gradle using
include 'root-proj-dir:dir1:dir2:...:----test'
where the directory structure is
root-proj-dir
|
|
----dir1
| |
| |
| ----dir2
| |
| |
| ....----test
----settings.gradle
|
----build.gradle
For more info on dealing with multi-module (or multi-project in Gradle terminology ) builds refer this link
I've multi-module gradle project. Let's say project parent has modules module1 and module2.
I have included both the modules in settings.gradle in the parent project as well.
When I declare the common dependencies in build.gradle of parent project, both the project is not compiling but when I add the dependencies in build.gradle of each module then the modules are compiling successfully.
Any Idea how can I do this.
You can declare dependencies for all modules in your project using the allprojects statement in your parent module. This is the essential way of doing so in your parent build.gradle file:
allprojects {
// Plugins can go here, example:
apply plugin: 'java'
dependencies {
// Dependencies go here, example:
compile group: 'org.apache.shiro', name: 'shiro-core', version: '1.4.0'
}
}
Check this and this answer for more insight on the configuration point of a multi project.
Also have a look at the Gradle documentation about this topic for a deep dive.
I have a project with two modules:
first one HostProject
second one SubProject
LibProject is a android apk project but has a jar task to make a jar from the code.
jar task:
task sourcesJar(type: Jar) {
from 'build/intermediates/classes/debug'
archiveName 'SubProject.jar'
}
In HostProject I want to use libproject's code by the jar file. Is there someway easy to add dependency?
HostProject build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
****compile project(':LibProject')****
}
gradle show error: resolves to an APK archive which is not supported as a compilation dependency
can I use the dependencies in HostProject's build.gradle without add new task?