Using the output classes path from a sub-project in another sub-project (For Hibernate tools)


(Paul Grove) #1

I know it sounds strange. But I have a war sub-project that has JPA code in, I also have another sub-project for all my database stuff. One of the tasks in the database project needs the compiled classes directory path for the classpath of the ant task for generating the DDL from the JPA meat data using the hbm2ddl tool. I have this working but feel it is a bit clunky as I currently iterate through all projects until I get the war project. code below

task ddlCreate(dependsOn:':war:classes', description : 'This task creates the file tables.sql with create table scripts (inside the folder database/db/base ) for the available entities in the project.')<<{
 def htcp = configurations.schemaExportAntTask
 ant {
  taskdef(name:'hibernatetool', classname:'org.hibernate.tool.ant.HibernateToolTask', classpath: htcp.asPath)
  hibernatetool(destdir:"generated"){
            def path
            rootProject.subprojects.each{project->
                if(project.name=='war'){
                    path = project.sourceSets.main.output.classesDir.path
                }
            }
            classpath (path: path)
   jpaconfiguration(persistenceunit: 'MobileGateway')
   hbm2ddl(drop:'false', create:'true', export:"false", format:"true", delimiter:";", outputfilename:"tables.sql")
  }
 }
}

Any ideas?


(Peter Niederwieser) #2

This can be simplified to ‘project(":war").sourceSets.main.output.classesDir’. Still, it feels a bit hacky to reach out into another project’s output directory.


(Paul Grove) #3

Tried the below

def path = project(":war").sourceSets.main.output.classesDir

Got the below error

* What went wrong:
Execution failed for task ':database:ddlDrop'.
> No such property: sourceSets for class: org.apache.tools.ant.UnknownElement

(Luke Daley) #4

This looks like Groovy’s closure symbol resolution.

Try:

def path = owner.project(":war").sourceSets.main.output.classesDir

The problem is that project(":war") is being interpreted as ant code.


(Paul Grove) #5

Same error I’m affraid

* What went wrong:
Execution failed for task ':database:ddlDrop'.
> No such property: sourceSets for class: org.apache.tools.ant.UnknownElement
  * Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':database:ddlDrop'.
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:68)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
 at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)
 at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)
 at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200)
 at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172)
 at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
 at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:111)
 at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
 at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
 at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
 at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
 at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
 at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
 at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
 at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
 at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247)
 at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)
 at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)
 at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)
 at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
 at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
 at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
 at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
 at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111)
 at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
 at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109)
 at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:103)
 at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
 at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
 at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
 at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
 at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
 at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
 at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)
 at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
 at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
 at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:42)
 at org.gradle.launcher.cli.RunBuildAction.execute(RunBuildAction.java:28)
 at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
 at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
 at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
 at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
 at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:31)
 at org.gradle.launcher.exec.ExceptionReportingAction.execute(ExceptionReportingAction.java:20)
 at org.gradle.launcher.Main.doAction(Main.java:48)
 at org.gradle.launcher.exec.EntryPoint.run(EntryPoint.java:45)
 at org.gradle.launcher.Main.main(Main.java:39)
 at org.gradle.launcher.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
 at org.gradle.launcher.ProcessBootstrap.run(ProcessBootstrap.java:32)
 at org.gradle.launcher.GradleMain.main(GradleMain.java:24)
 at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
 at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
 at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
Caused by: groovy.lang.MissingPropertyException: No such property: sourceSets for class: org.apache.tools.ant.UnknownElement
 at build_6et9hjhjnsn66anr7808f6b7qe$_run_closure3_closure13_closure14.doCall(/Users/H06810659/dev/source/mobileuk/xxxxxxxx/mg/database/build.gradle:19)
 at build_6et9hjhjnsn66anr7808f6b7qe$_run_closure3_closure13_closure14.doCall(/Users/H06810659/dev/source/mobileuk/xxxxxxx/mg/database/build.gradle)
 at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(BasicAntBuilder.java:86)
 at org.gradle.api.internal.project.DefaultAntBuilder.super$3$invokeMethod(DefaultAntBuilder.groovy)
 at org.gradle.api.internal.project.DefaultAntBuilder.invokeMethod(DefaultAntBuilder.groovy:37)
 at build_6et9hjhjnsn66anr7808f6b7qe$_run_closure3_closure13.doCall(/Users/H06810659/dev/source/mobileuk/xxxxx/mg/database/build.gradle:18)
 at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)
 at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)
 at org.gradle.api.internal.project.AbstractProject.ant(AbstractProject.java:844)
 at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:196)
 at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:102)
 at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:99)
 at org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod(Unknown Source)
 at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.groovy:73)
 at build_6et9hjhjnsn66anr7808f6b7qe$_run_closure3.doCall(/Users/H06810659/dev/source/mobileuk/xxxx/mg/database/build.gradle:16)
 at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:452)
 at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:436)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:60)
 ... 56 more

(Luke Daley) #6

Safest way…

def warProject = project(":war")
task ddlCreate(dependsOn:':war:classes', description …
…
  def path = warProject.sourceSets.main.output.classesDir