Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Script Execution #53

Closed
Fallout86 opened this issue Apr 6, 2016 · 10 comments
Closed

Problem with Script Execution #53

Fallout86 opened this issue Apr 6, 2016 · 10 comments

Comments

@Fallout86
Copy link

@keeganwitt

Hi,

I'm trying to to run a script inside the script tag, which in general works, but inside the script I try to invoke a method of a different Groovy Class. I get the following error:

Error occurred while calling a method on a Groovy class from classpath. InvocationTargetException: No such property: Eclipse for class: Script1

With the old Gmaven Plugin I could just use the scriptpath Tag to load all the Groovy Classes of one folder. Is there any equivalent for your plugin?

@keeganwitt
Copy link
Member

It looks like maybe you're using a class called Eclipse, but are missing an import for it? I couldn't say for sure without seeing the part of the script in question. If you'd like me to confidentially take a look you can shoot me an email (keeganwitt@gmail.com).

@dawez
Copy link

dawez commented Apr 8, 2016

I also have an issue when I am trying to import and external class. I described the problem here: http://stackoverflow.com/questions/36471417/

Is there anything that I missed , or is there a way to setup a classpath for loading the classes outside the main script ?

@keeganwitt
Copy link
Member

I'm not sure you're both talking about the same issue. Are you both talking about importing a class from another Groovy script? A class from your project? Or a class from a dependency? If you're talking about importing from another Groovy script, how did you include the dependent script in the scrip that needs it? With something like def myDependentScript = new GroovyClassLoader().parseClass(new File("myScriptDependency.groovy")).newInstance()? Currently I think that'd be the only way to do it. I've thought about offering an option to do the parseClass() within GMavenPlus so you don't have to, but I want to think some more about what kind of complications that'd introduce, particularly with regard to sharing the classpath between the scripts so you can have scripts include other scripts and also your Maven dependencies.

@dawez
Copy link

dawez commented Apr 11, 2016

@keeganwitt , correct and thank you. I implemented the GroovyClassLoader()... and managed to split my single groovy script into separate classes.

@Fallout86
Copy link
Author

@keeganwitt in general I have a folder with several groovy classes on a server. Those classes are used inside a small groovy script, which I implemented via the script tag. I already tried your solution, but it just post pones the problem. Since the different classes are using each other.

@keeganwitt
Copy link
Member

@dawez Awesome! I created #54 to track the idea of doing the parsing for you.

@keeganwitt
Copy link
Member

@Fallout86 Are those classes compiled sources in your GMavenPlus project?

@Fallout86
Copy link
Author

@keeganwitt In this project yes, but in general they are stored on a server and used during the deploy phase.

Here is the code snippet with gmaven:

`

    <plugins>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>groovy-maven-plugin</artifactId>
        <version>2.0</version>
        <executions>
          <execution>
            <id>foo</id>
            <phase>deploy</phase>
            <configuration>
              <scriptpath>
                <element>${path to the script folder}</element>
              </scriptpath>
              <source>
              <![CDATA[
                    if(new java.io.File("${a speficifc file}).exists()) {
                        FooRunner.run() { FooFunctions foo -> foo.with {
                               doSomething(project.groupId, project.artifactId, project.version)
                             }
                        }
                    }
              ]]>
              </source>
            </configuration>
            <goals>
              <goal>execute</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>foo.bar</groupId>
            <artifactId>control-groovy-libs</artifactId>
            <version>1.0.0</version>
            <type>pom</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>

  </build>

`

I hope this helps a bit more to understand my problem

@keeganwitt
Copy link
Member

groovy-maven-plugin is not GMavenPlus, it's GMaven. Also, it looks like you're not compiling these sources, just executing them. If that's the case, then the method I described to dawez should work for you also.

@keeganwitt
Copy link
Member

I think we can close this thread since we have #54 to track the remaining idea. Feel free to reopen if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants