Summary
My main project uses a library project and compiles happily.
But I also have a Groovy custom task that internally uses “project.configurations.compile.asPath
”. This returns the jar version of the library project, but the jar is never created during the invocation so the task fails.
How can I tell Gradle to create the jar of the library before running the custom task? Or is there another way to solve this?
Some Details
The main project “MAIN” uses the library project “MYLIB” with the following settings.gradle:
rootProject.name = 'MAIN'
include 'MYLIB'
project(':MYLIB').projectDir = "../../somefolder/MYLIB" as File
The MYLIB is added to the MAIN compile classpath in build.gradle:
dependencies {
compile project(':MYLIB')
}
The custom task uses a modified configuration “hibtools
” in order to add a library:
configurations {
hibtools {
extendsFrom configurations.compile
}
}
dependencies {
hibtools 'org.hibernate:hibernate-tools:5.+'
}
The custom task “dbSchema
” is defined as follows:
task dbSchema(dependsOn: [classes], type: com.ex.DbSchemaTask) {
outputfilename = "some.sql"
}
The implementation of the custom task “com.ex.DbSchemaTask.groovy
” uses the “hibtools
” classpath:
ant.taskdef(name: 'hibernatetool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: project.configurations.hibtools.asPath
)
When I invoke the dbSchema task with “gradlew dbSchema
”, the ant.taskdef method receives a classpath containing the jar version of the library “MYLIB\build\libs\MYLIB-0.0.7.jar
” but that file is missing and the task fails.
Versions
gradlew -version
------------------------------------------------------------
Gradle 3.5
------------------------------------------------------------
Build time: 2017-04-10 13:37:25 UTC
Revision: b762622a185d59ce0cfc9cbc6ab5dd22469e18a6
Groovy: 2.4.10
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_121 (Oracle Corporation 25.121-b13)
OS: Windows 10 10.0 amd64