I have problem with include local jar file.
I have two projects:
ProjectA
ProjectB
--libs
----jgrapht-jdk1.6.jar
My build file include (This is the part that concerns projectB):
project(':ProjectB') {
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
compileOnly
}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
dependencies {
compileOnly files('libs/jgrapht-jdk1.6.jar')
compile 'org.simpleframework:simple-xml:2.7#jar'
}}
I run command gradlew -q dependencies and see result
Project :ProjectB
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
\--- org.simpleframework:simple-xml:2.7
compileOnly
No dependencies
default - Configuration for default artifacts.
\--- org.simpleframework:simple-xml:2.7
runtime - Runtime classpath for source set 'main'.
\--- org.simpleframework:simple-xml:2.7
testCompile - Compile classpath for source set 'test'.
\--- org.simpleframework:simple-xml:2.7
testRuntime - Runtime classpath for source set 'test'.
\--- org.simpleframework:simple-xml:2.7
Line compile 'org.simpleframework:simple-xml:2.7#jar' - working fine,
but line compileOnly files('libs/jgrapht-jdk1.6.jar') don't work.
I use gradle 1.8, Windows 7 x64
Tell me please where I made a mistake.
It's a known limitation that file dependencies aren't currently shown by gradle dependencies. They nevertheless work (if the paths are right).
Related
I have root gradle project which needs to have a small Spring Boot subproject. This subproject will be deployed in the same pod as root project, so it needs to be built whenever root project is built. I tried by creating the following structure:
subproject/
├─ src/...
├─ build.gradle
settings.gradle
with the following contents:
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'root'
include 'subproject'
build.gradle:
plugins {
id 'org.springframework.boot' version '2.7.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.demo'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
But when I refresh the project from within the IDEA, it shows Task 'wrapper' not found in project ':subproject'. What did miss? This subproject cannot exist by itself and shouldn't have a 'wrapper', it should be build by the root project.
$ ./gradlew -q projects
Root project 'root'
+--- Project ':subproject'
Gradle version: 6.8.3, Java version: 11
The problem actually does not exist. Everything is correct, except that IDEA added subproject as separate gradle project (I guess). So when I hit refresh, it could not be performed because IDEA was trying to find wrapper in the subproject. Simply saying, if you have such problem, check how many projects you have in your IDEA's Gradle view. In my case, there was two - root and subproject, the latter is unneeded.
I'm newbie with Gradle and i'm starting to apply it to an existing project.
What i would like to do is compile java classes using the compileJava task of the java plugin.
I followed the documentation to add all of the jars contained to my local directory but it doesn't seem to work.
When i run the compileJava task it continues to print messages like
"javax.servlet.http does not exist"
"javax.servlet does not exist"
etc.
etc.
It prints messages as above for every package contained in my local folder and even if i try to print dependencies using the 'gradle dependencies' command it prints:
annotationProcessor - Annotation processors and their dependencies for
source set 'main'. No dependencies
apiElements - API elements for main. (n) No dependencies
archives - Configuration for archive artifacts. No dependencies
compile - Dependencies for source set 'main' (deprecated, use
'implementation ' instead). No dependencies
compileClasspath - Compile classpath for source set 'main'. No
dependencies
compileOnly - Compile only dependencies for source set 'main'. No
dependencies
default - Configuration for default artifacts. No dependencies
implementation - Implementation only dependencies for source set
'main'. (n) No dependencies
runtime - Runtime dependencies for source set 'main' (deprecated, use
'runtimeOnly ' instead). No dependencies
runtimeClasspath - Runtime classpath of source set 'main'. No
dependencies
runtimeElements - Elements of runtime for main. (n) No dependencies
runtimeOnly - Runtime only dependencies for source set 'main'. (n) No
dependencies
testAnnotationProcessor - Annotation processors and their dependencies
for source set 'test'. No dependencies
testCompile - Dependencies for source set 'test' (deprecated, use
'testImplementation ' instead). No dependencies
testCompileClasspath - Compile classpath for source set 'test'. No
dependencies
testCompileOnly - Compile only dependencies for source set 'test'. No
dependencies
testImplementation - Implementation only dependencies for source set
'test'. (n) No dependencies
testRuntime - Runtime dependencies for source set 'test' (deprecated,
use 'testRuntimeOnly ' instead). No dependencies
testRuntimeClasspath - Runtime classpath of source set 'test'. No
dependencies
testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies
So...it can't get the dependencies properly.
I've tryied to get one dependency from a remote repository as mavencentral() or jcenter and everything works fine.
Can someone help me? Is there something that i'm making in the wrong way? It seems that fileTree is not working fine.
This is my gradle.build file:
plugins {
id 'java'
}
//Source and target compatibility.
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
//Libraries local repository.
repositories {
flatDir {
dirs 'src/main/webapp/WEB-INF/lib'
}
}
dependencies {
compile fileTree(dir:'src/main/webapp/WEB-INF/lib', include: ['*.jar'])
}
//Source sets.
sourceSets {
//Thes configuration under 'main' will be used for the production environment.
main {
java {
//Source directory of the java files.
srcDir 'src/main/webapp/WEB-INF/classes'
}
//.class files output directory
java.outputDir = file('src/main/webapp/WEB-INF/classes')
}
}
I have a fairly simple setup, that does not work and I cannot work out why:
the folder structure is as follows:
/dependency
/build.gradle
/settings.gradle
/src/main/...
/Mainproject
/build.gradle
/settings.gradle
/Subproject_1
/build.gradle
/src/main...
/Subproject_2
/build.gradle
/src/main...
I want the Subproject to depend on "dependency" locally for quick testing.
so I stuck to the manual and did:
/Mainproject/settings.gradle:
include "Subproject_1", "Subproject_2", "dependency"
project(":dependency").projectDir = file('../dependency')
/Mainproject/build.gradle:
allprojects {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
dependencies {
compile project(':Subproject_1')
compile project(':Subproject_2')
}
/dependency/build.gradle:
version '1.0'
apply plugin: 'java'
repositories {
maven {
url "http://...."
}
}
dependencies {
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'javax', name: 'javaee-api', version: '7.0'
}
jar {
manifest {
attributes 'Implementation-Title': 'Archive delegation dispatcher classes',
'Implementation-Version': project.version
}
}
The build.gradle files of Subproject_1 and _2 are empty.
The settings.gradle file of dependency is empty.
When i gradle build MainProject i get:
Circular dependency between the following tasks:
:dependency:classes
\--- :dependency:compileJava
\--- :dependency:jar
\--- :dependency:classes (*)
(*) - details omitted (listed previously)
And I cannot get my head around why that would be.
Any hints?
When you include "dependency" in your Mainproject's settings.gradle file, you are making the "dependency" project a subproject of "Mainproject".
Then this block in your Mainproject's build.gradle file defines "dependency" as a compile dependency of all subprojects.
allProjects {
dependencies {
compile project(path: ':dependency')
}
}
Since the "dependency" project is also a subproject, you have a circular dependency defined where the "dependency" project depends on itself.
Instead, try creating a settings.gradle file for each of the subprojects with the following:
include "dependency"
project(":dependency").projectDir = file('../dependency')
Then modify your settings.gradle file for the Mainproject to look like this:
include "Subproject_1", "Subproject_2"
You've stated that allProjects have a dependency on the project dependency as seen here:
allprojects {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
You need this to only apply to your projects that aren't dependency. You can do that by excluding it when applying dependencies, like this
subprojects { project ->
if (project.name != "dependency") {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
}
Because dependencies itself.
Move it must be OK.
Turning off Instant run worked for me, could work for someone else too. I had some changes related to gradle and my application appeared not to work after it.
build.gradle (:shared)
This is because you are trying to include a module inside of yourself.
From:
dependencies {
implementation project(':shared')
...
}
To:
dependencies {
...
}
GL
Source
I have the following build script (webapp:build.gradle):
apply plugin: 'java'
dependencies {
project(':api')
}
When I run gradle dependencies webapp:dependencies in command line I get:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
:webapp:dependencies
------------------------------------------------------------
Project :webapp
------------------------------------------------------------
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
No dependencies
default - Configuration for default artifacts.
No dependencies
runtime - Runtime classpath for source set 'main'.
No dependencies
testCompile - Compile classpath for source set 'test'.
No dependencies
testRuntime - Runtime classpath for source set 'test'.
No dependencies
There was nothing to be said about dependency from api project. Why? What's wrong?
Because You haven't specified configuration name for this dependency. It should be e.g.:
dependencies {
compile project(':api')
}
webapp/build.gradle
apply plugin: 'java'
dependencies {
compile project(':api')
}
webapp/settings.gradle
include 'api'
webapp/api/build.gradle
apply plugin: 'java'
In my project I use some local dependencies:
dependencies {
compile files('lib/mylib.jar')
}
Why when I call gradle dependencies I can't see this library as a dependency? Command gradle dependencies --configuration compile returns this:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
No dependencies
Dependencies downloaded from repository (maven/ivy) are visible. For example:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:14.0.1'
}
will show:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
\--- com.google.guava:guava:14.0.1
BUILD SUCCESSFUL
I should also add that dependencies are not shown but project compiles properly.
Gradle documentation on file dependency explains
File dependencies are not included in the published dependency descriptor for your project. However, file dependencies are included in transitive project dependencies within the same build. This means they cannot be used outside the current build, but they can be used with the same build.
Use api(name: 'mylib', ext: 'jar') as a workaround.