Hallo,
I have a problem. I want to use within my gradle buildscrip the javaexec {
… } method so, that it knows my classpath, that I set in my buildscript. That is the code:
repositories {
maven {
credentials {
username repoUsername
password repoPassword
}
url 'http://artifacts.westernacher.com:8081/artifactory/aggregated-releases'
}
maven {
credentials {
username repoUsername
password repoPassword
}
url 'http://artifacts.westernacher.com:8081/artifactory/aggregated-snapshots'
}
// Here is the important part:
configurations{ buildDependencies }
dependencies { buildDependencies(
'org.alfresco.enterprise:alfresco-mmt:4.0.0') }
// add libs to script classpath
configurations.buildDependencies.each {File file -> GroovyObject.class.classLoader.addURL(file.toURL()) }
}
void aMethod(){
def exit = javaexec {
// I do not use this so
classpath project.configurations.buildDependencies
main = "com.simontuffs.onejar.Boot"
args = [
"install",
ampFile,
warFile,
"-force",
"-nobackup"
].toList()
}
}
The problem is, that I do not want to use the first part:
// inside repositories ...
configurations{ buildDependencies }
dependencies { buildDependencies(
'org.alfresco.enterprise:alfresco-mmt:4.0.0') }
// add libs to script classpath
configurations.buildDependencies.each {File file -> GroovyObject.class.classLoader.addURL(file.toURL()) }
I want to change my coode like that:
dependencies { classpath (
'org.alfresco.enterprise:alfresco-mmt:4.0.0') }
But then I can not call the javaexec method, because it does not know the ‘org.alfresco.enterprise:alfresco-mmt:4.0.0’ dependency.
What can I do? How can I use the javaexec method so that it knows the “org.alfresco.enterprise:alfresco-mmt:4.0.0” dependency?
Thanks very much for your help!
Best regards & Shalom Amin Zamani
If you need the Alfresco dependency only for ‘javaexec’, you don’t need to (and should not) add it to the build script class path. Not sure why the ‘classLoader.addURL’ workaround would be necessary.
Hallo Peter,
thank you for your reply. I have removed the classLoader.addURL section and set the alfresco dependency so:
buildscript {
repositories {
maven {
credentials {
username repoUsername
password repoPassword
}
url 'http://xzy'
}
maven {
credentials {
username repoUsername
password repoPassword
}
url 'http://xyz'
}
// Add here your classpath libs / build dependencies
dependencies {
classpath ( 'org.alfresco.enterprise:alfresco-mmt:4.0.2' )
}
}
}
But now when I want to start javaexec:
def exit = project.javaexec {
//classpath project.configurations.buildDependencies
main = "com.simontuffs.onejar.Boot"
args = [
"install",
ampFile,
warFile,
"-force",
"-nobackup"
].toList()
}
I get following error:
java.lang.NoClassDefFoundError: com/simontuffs/onejar/Boot
[exec] Caused by: java.lang.ClassNotFoundException: com.simontuffs.onejar.Boot
[exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[exec] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[exec] Could not find the main class: com.simontuffs.onejar.Boot. Program will exit.
[exec] BUILD FAILED
So how do I have to start it? Thank you very much for your help!
Best regards
& Shalom Amin Zamani
The Problem is that the javaexec needs the alfresco dependency, there is a class inside of the dependency that is needed ( I guess).
Shalom Amin Zamani
As I already tried to explain, you should pass the Alfresco dependency only to ‘javaexec’. There is no need to set it as a build script dependency.
Hi,
thanks for replying so soon. My Gradle knowledge is not so good. Can you tell my how I can pass it only to javaexec?
I have tried the following:
def exit = project.javaexec {
classpath "org.alfresco.enterprise:alfresco-mmt:4.0.2"
main = "com.simontuffs.onejar.Boot"
args = [
"install",
ampFile,
warFile,
"-force",
"-nobackup"
].toList()
}
But this does not work. Then I get following error:
Execution failed for task ‘:buildWarWithAmps’.
[exec] > Cannot convert URL 'org.alf
[exec] BUILD FAILED
[exec] Total time: 17.416 secs
[exec] resco.enterprise:alfresco-mmt:4.0.2’ to a file.
Thank you very much when you can help me!
Shalom Amin Zamani
You can help yourself, by studying the Gradle documentation. You have to declare a configuration, add the Alfresco dependency, and pass the configuration to ‘javaexec’, similar to what you already had earlier. However,all of this should happen outside ‘buildscript { … }’. ‘javaexec’ will fork a new process, hence the build script class path is irrelevant here.
rgauss
(Ray Gauss II)
July 27, 2012, 3:24pm
8
Hi Amin,
Also have a look at the alfresco-gradle-plugins project.
Regards,
Ray
Hi Ray,
thanks for you answer. I have done a look to the plugin, but it does not support many functions.
rgauss
(Ray Gauss II)
July 27, 2012, 5:14pm
10
I’d say it supports quite a few functions, including the installAmp task which seems to be exactly what you’re trying to do.
Hi …
Thank you very much for your help! You are right. But it seems for me a little bit too much, to integrate a new plugin only because I want to use a project.javaexec command rightly. -;(
Hi, can soemone please delete the repository URL of my initial post?
Sorry, we cannot edit posts (getsatisfaction lmitation, hopefully resolved in future)
configurations {
alfresco
}
dependencies {
alfresco "org.alfresco.enterprise:alfresco-mmt:4.0.2"
}
task alfresco(type: JavaExec) {
classpath configurations.alfresco
main = "com.simontuffs.onejar.Boot"
args "install", ampFile, warFile, "-force", "-nobackup"
}
4 Likes