Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EFB8B18684 for ; Sun, 4 Oct 2015 07:29:53 +0000 (UTC) Received: (qmail 69428 invoked by uid 500); 4 Oct 2015 07:29:53 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 69391 invoked by uid 500); 4 Oct 2015 07:29:53 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 69381 invoked by uid 99); 4 Oct 2015 07:29:53 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Oct 2015 07:29:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2F7361A0874 for ; Sun, 4 Oct 2015 07:29:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id cV-AEP3CaVv4 for ; Sun, 4 Oct 2015 07:29:44 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id EBFE4201F9 for ; Sun, 4 Oct 2015 07:29:43 +0000 (UTC) Received: from [10.17.0.145] ([94.56.107.152]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0LyEJp-1af1774BWf-015dEB for ; Sun, 04 Oct 2015 09:29:37 +0200 Subject: Re: IntelliJ/Maven/GMavenPlus project, groovy scripts and run CLASSPATH To: users@groovy.incubator.apache.org References: <560CE0D6.6080802@gmx.com> From: Maarten Boekhold Message-ID: <5610D55F.5080302@gmx.com> Date: Sun, 4 Oct 2015 11:29:35 +0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------040207070607010008030108" X-Provags-ID: V03:K0:GyC+H+UaeVsdN3C198FY6I+V+IaoTY5YT05tTOtMLWknyecJRf6 FkAsGU4Ea328C5F3O4kl1teRXW2pQlh872uL9jVvlKXtOQlERXoUBoUP76oRkRlobSSNJmy urOnH3fricQeDfTDhCNAFJZjRJjxIvTusJIDWwvDxRQCCguA86ohASb04eLBQIMEZBqqZua TScNW8x0xwZO2iZH4I+OQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:doCEGVqK2aM=:NFZ5TQaEd8igBQungzwJBq cRhmGpVKoplKt8ochUc3l1GeaF0ynUg9bGIsmgS9yLfhCv0ZWx/kUCz8VPtn2XNuNlMSs4yeu q15TJyxxWbGHR47ndidr2OWVC7Zkxtc6aCNl/hXQpSOF9mSIP7zfah2pFGz76p2xb6PR0fC98 SgRlVqJXu8ZF3aMpiVh092UOPm5a7DGXCiQ2lmczblc4HJkwc3m3x50iD7vjeCl8xPn+z6skg VNUInjGkeZxFv5CDBzl6PjM3Akuf1HSRO26N48T3x+nk3fkcs+/iCEtQGZl0WmnMDCRT5/uNk PaERn39azsBtSpvktiyZGLoUnVSX68lBdJ42nuk50wWBxhn90aQWAi42e7iRJ/2ulc9jswvZY cBkdSQxM0ulNdSwuAweR7UvNvcSmLegGi1GQiQbdGUE0BWOAisYnKqD5I1tgDrb9Ur5usv49v i6Va6SuAkkrJodIifOxUeZDot0aVS46yPnUofDNHruNtOH9EDcLwu3F6lWpsU6rLybzViVbVi 9Nh3WyFVUR3nPph+6QK2VveVDcn9QDNNKi6qTqU0T0BKarPBRqwYd5RIR6P82+vFfrbqDsbLh JkVpIu5KDgaKPt3vhPIcxTz3M2VqivrxmImxKQye8wVjKV4K0TNLfwR/aLICi6YpT41OidkXh wsIrhtJsL7K/ZSgVcLhjfxZm2YMB2cuvbLim35P602EY/8avVc5/S+gcfP0KM5QPIS3fSUXIC IA3dVf0+YqK2cJyhcJm3vj49tfZqBES0bNEP1wwBzsUQCWykaBL5wF5w6nsnJpLZ+STci+CVV 0UDusJz This is a multi-part message in MIME format. --------------040207070607010008030108 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Keegan, Let me describe how everything is normally run in "deployed mode", and then what my development environment in maven/IntelliJ looks like. Deployed mode: * Java code/jars are installed in ${dir}/lib * Groovy code installed in ${dir}/scripts o This is a mix of interface declarations, 'real classes' and scripts, uncompiled * Start/stop scripts in ${dir}/etc * CLASSPATH /only/ has the JAR files from under ${lib} in it! * When running the program, a configuration file tells the application to load/parseClass() all groovy files under ${dir}/scripts using a GroovyClassLoader instance. There is some logic there to load/parse things in order so as to handle dependency issues between classes/scripts. The resulting classes are cached in a Map. Based on certain events (data mapping requests) a class instance is retrieved from the Map, instantiated and run. o In fact, the application uses the JSR223 API to load things, and under the hood, that uses GroovyClassLoader.parseClass() Maven/IntelliJ: * Java code under src/main/java * Groovy code under src/main/groovy * From the "Maven Projects" tool window, I use "mvn clean compile" to compile all code. This *also* compiles all groovy files and generates class files under target/classes! * I have a "Run Configuration" that uses the "classpath of module". * The configuration file tells the main application "load all groovy files under src/main/groovy" * The problem here is that when building the project, 'mvn clean compile' also compiles all groovy scripts to target/classes. * When I now run my run configuration, the /groovy classes/interfaces/ are already on the CLASSPATH, so there's a conflict between running the scripts as loaded by GroovyClassLoader.parseClass() and the ones that are already on the classpath. I'm getting lots of GroovyClassCastExceptions because it's trying to cast to classes that are loaded by a different classloader (eg from the classpath). This is the thing I need to avoid/fix. o I also need to write unit tests for the groovy code, and for that I do need all groovy code on the test-classpath, just to complicate things a bit more. Btw for those unit tests there's no loading of classes via GroovyClassLoader/jsr223 involved, so that makes things a bit simpler again. I could of course just remove GMavenPlus from my pom.xml, but then my groovy code isn't compiled at all, and I do want that "safety net" to capture errors in that part of the (groovy) code. Still a bit of a complicated description I guess, but I hope it's a little bit more clear what I'm trying to achieve now. Maarten On 2015-10-04 07:16, Keegan Witt wrote: > How about adding them in a non-standard directory (to avoid IntelliJ > knowing where they are) then add them as test sources to GMavenPlus? > If that'd work, please see here > for > an example. It might not though, because I'm not sure I'm fully > understanding your use case. It wasn't clear to me how you were > deploying the scripts so you could do the > GroovyClassLoader.parseClass() calls in production. > > -Keegan > > On Thu, Oct 1, 2015 at 3:29 AM, Maarten Boekhold > wrote: > > Hi all, > > Not strictly a groovy-specific question I believe, but I also > believe that if anybody knows the answer to this, they'll be on > this list. > > I am working on a project that is mixed Java and groovy code. I'm > developing in IntelliJ, it's a maven project that is using > GMavenPlus (1.5). > > When the resulting artifact is run after I have installed it, the > groovy scripts should***not* be on the CLASSPATH of the > application; instead they are loaded dynamically > (GroovyClassLoader.parseClass()). So, also inside IntelliJ, when > running or debugging the full application, I want to exclude the > groovy sources (or compiled artifacts) from the CLASSPATH. > However, while developing I *do* want these scripts to be > *compiled *so I can see any errors. Also when running unit tests > the scripts will need to be on the classpath. > > I'm looking for a way to achieve the following: > - Groovy sources are compiled when building the project > - Groovy artifacts are NOT on the CLASSPATH when running/debugging > the application inside IntelliJ > - Groovy artifacts ARE on the CLASSPATH when running unit tests > > Does anybody have any idea how to do this? > > Maarten > > --------------040207070607010008030108 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Keegan,

Let me describe how everything is normally run in "deployed mode", and then what my development environment in maven/IntelliJ looks like.

Deployed mode:
  • Java code/jars are installed in ${dir}/lib
  • Groovy code installed in ${dir}/scripts
    • This is a mix of interface declarations, 'real classes' and scripts, uncompiled
  • Start/stop scripts in ${dir}/etc
  • CLASSPATH only has the JAR files from under ${lib} in it!
  • When running the program, a configuration file tells the application to load/parseClass() all groovy files under ${dir}/scripts using a GroovyClassLoader instance. There is some logic there to load/parse things in order so as to handle dependency issues between classes/scripts. The resulting classes are cached in a Map. Based on certain events (data mapping requests) a class instance is retrieved from the Map, instantiated and run.
    • In fact, the application uses the JSR223 API to load things, and under the hood, that uses GroovyClassLoader.parseClass()

Maven/IntelliJ:
  • Java code under src/main/java
  • Groovy code under src/main/groovy
  • From the "Maven Projects" tool window, I use "mvn clean compile" to compile all code. This *also* compiles all groovy files and generates class files under target/classes!
  • I have a "Run Configuration" that uses the "classpath of module".
  • The configuration file tells the main application "load all groovy files under src/main/groovy"
  • The problem here is that when building the project, 'mvn clean compile' also compiles all groovy scripts to target/classes.
  • When I now run my run configuration, the groovy classes/interfaces are already on the CLASSPATH, so there's a conflict between running the scripts as loaded by GroovyClassLoader.parseClass() and the ones that are already on the classpath. I'm getting lots of GroovyClassCastExceptions because it's trying to cast to classes that are loaded by a different classloader (eg from the classpath). This is the thing I need to avoid/fix.
    • I also need to write unit tests for the groovy code, and for that I do need all groovy code on the test-classpath, just to complicate things a bit more. Btw for those unit tests there's no loading of classes via GroovyClassLoader/jsr223 involved, so that makes things a bit simpler again.

I could of course just remove GMavenPlus from my pom.xml, but then my groovy code isn't compiled at all, and I do want that "safety net" to capture errors in that part of the (groovy) code.

Still a bit of a complicated description I guess, but I hope it's a little bit more clear what I'm trying to achieve now.

Maarten

On 2015-10-04 07:16, Keegan Witt wrote:
How about adding them in a non-standard directory (to avoid IntelliJ knowing where they are) then add them as test sources to GMavenPlus?  If that'd work, please see here for an example.  It might not though, because I'm not sure I'm fully understanding your use case.  It wasn't clear to me how you were deploying the scripts so you could do the GroovyClassLoader.parseClass() calls in production.

-Keegan

On Thu, Oct 1, 2015 at 3:29 AM, Maarten Boekhold <boekhold@gmx.com> wrote:
Hi all,

Not strictly a groovy-specific question I believe, but I also believe that if anybody knows the answer to this, they'll be on this list.

I am working on a project that is mixed Java and groovy code. I'm developing in IntelliJ, it's a maven project that is using GMavenPlus (1.5).

When the resulting artifact is run after I have installed it, the groovy scripts should not be on the CLASSPATH of the application; instead they are loaded dynamically (GroovyClassLoader.parseClass()). So, also inside IntelliJ, when running or debugging the full application, I want to exclude the groovy sources (or compiled artifacts) from the CLASSPATH. However, while developing I do want these scripts to be compiled so I can see any errors. Also when running unit tests the scripts will need to be on the classpath.

I'm looking for a way to achieve the following:
- Groovy sources are compiled when building the project
- Groovy artifacts are NOT on the CLASSPATH when running/debugging the application inside IntelliJ
- Groovy artifacts ARE on the CLASSPATH when running unit tests

Does anybody have any idea how to do this?

Maarten


--------------040207070607010008030108--