I amb writing a small component which needs to pull data from a Google BigQuery table to later save that as Party.
So I created a new component for which I have a service with one single action to call a script and a script. On the component I also added a build.gradle to add the dependency to google bigquery.
Problem is that when I try to import the bigquery libraries from the script it says it can't find them.
component/mycomponent/{data,entity,screen,script,service}
mycomponent/component.xml:
<?xml version="1.0" encoding="UTF-8"?>
<component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/moqui-conf-2.1.xsd"
name="mycomponent" version="${moqui_version}">
</component>
mycomponent/build.gradle:
apply plugin: 'groovy'
sourceCompatibility = '1.8'
def moquiDir = file(projectDir.absolutePath + '/../../..')
def frameworkDir = file(moquiDir.absolutePath + '/framework')
// maybe in the future: repositories { mavenCentral() }
repositories {
flatDir name: 'localLib', dirs: frameworkDir.absolutePath + '/lib'
jcenter()
}
dependencies {
compile project(':framework')
testCompile project(':framework').configurations.testCompile.allDependencies
compile 'com.google.cloud:google-cloud-bigquery:1.40.0'
}
// by default the Java plugin runs test on build, change to not do that (only run test if explicit task)
// no longer workds as of gradle 4.8 or possibly earlier, use clear() instead: check.dependsOn.remove(test)
check.dependsOn.clear()
test {
dependsOn cleanTest
dependsOn ':runtime:component:mantle-usl:test'
systemProperty 'moqui.runtime', moquiDir.absolutePath + '/runtime'
systemProperty 'moqui.conf', 'conf/MoquiDevConf.xml'
systemProperty 'moqui.init.static', 'true'
// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true; testLogging.showExceptions = true
classpath += files(sourceSets.main.output.classesDirs)
// filter out classpath entries that don't exist (gradle adds a bunch of these), or ElasticSearch JarHell will blow up
classpath = classpath.filter { it.exists() }
beforeTest { descriptor -> logger.lifecycle("Running test: ${descriptor}") }
}
mycomponent/services/myservice.xml:
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-2.1.xsd">
<service verb="sync" noun="myservice">
<in-parameters/>
<out-parameters/>
<actions>
<script location="component://mycomponent/script/pullClientesBQ.groovy" />
</actions>
</service>
</services>
mycomponent/script/pullClientesBQ.groovy:
import com.google.cloud.bigquery.BigQuery
import com.google.cloud.bigquery.BigQueryOptions
import com.google.cloud.bigquery.FieldValueList
import com.google.cloud.bigquery.QueryJobConfiguration
// Script code follows.
Then I go to the Tools web interface to run the service and:
17:47:13.788 ERROR 110121908-17 o.m.i.a.XmlAction Error running groovy script (org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: component___intermegaBaseClientes_script_pullClientesBQ_groovy: 1: unable to resolve class com.google.cloud.bigquery.BigQuery @ line 1, column 1. import com.google.cloud.bigquery.BigQuery
So, how can I (properly) use external libraries on my component's scripts?
thanks