Kris
Kris

Reputation: 479

phantomjs-maven-plugin : error Could not find a suitable constructor

I am trying to run the com.github.klieber.phantomjs-maven-plugin alone before trying to run it with com.github.searls.jasmine-maven-plugin.

The final goal is to be able to run Javascripts tests in maven then in Jenkins.

But I always have the same error :

    [ERROR] Failed to execute goal com.github.klieber:phantomjs-maven-plugin:0.7:install (default) on project my-jasmine-project: Execution default of goal com.gith
    ub.klieber:phantomjs-maven-plugin:0.7:install failed: Unable to load the mojo 'install' (or one of its required components) from the plugin 'com.github.klieber:
    phantomjs-maven-plugin:0.7': com.google.inject.ProvisionException: Guice provision errors:
    [ERROR]
    [ERROR] 1) Could not find a suitable constructor in com.github.klieber.phantomjs
    .mojo.InstallPhantomJsMojo. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
    [ERROR] at com.github.klieber.phantomjs.mojo.InstallPhantomJsMojo.class(Unknown
    Source)
    [ERROR] while locating com.github.klieber.phantomjs.mojo.InstallPhantomJsMojo
    [ERROR] at ClassRealm[plugin>com.github.klieber:phantomjs-maven-plugin:0.7, parent: sun.misc.Launcher$AppClassLoader@f4a24a]
    [ERROR] while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=com.github.klieber:phantomjs-maven-plugin:0.7:install)
    [ERROR]
    [ERROR] 1 error
    [ERROR] role: org.apache.maven.plugin.Mojo
    [ERROR] roleHint: com.github.klieber:phantomjs-maven-plugin:0.7:install

I created a maven project with

    mvn archetype:generate  -DarchetypeGroupId=com.github.searls
    -DarchetypeArtifactId=jasmine-archetype
    -DarchetypeVersion=RELEASE
    -DjasminePluginVersion=2.1
    -DgroupId=com.acme
    -DartifactId=my-jasmine-project
    -Dversion=0.0.1-SNAPSHOT

and here is the pom where I try to only install Phantom JS

  <build>
    <plugins>
      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>0.7</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.7</version>
        </configuration>
      </plugin>
    </plugins>
  </build>

Could you tell me what I am doing wrong ?

Thanks in advance,

Upvotes: 1

Views: 2125

Answers (2)

Kris
Kris

Reputation: 479

I found an other solution for running Javascripts tests in maven then in Jenkins

Below is how I use it in my POM:

                <!-- Install phantom JS binaries. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>org.phantomjs</groupId>
                                        <artifactId>phantomjs</artifactId>
                                        <version>${phantomjs.version}</version>
                                        <type>${phantomjs.packaging}</type>
                                        <classifier>${phantomjs.classifier}</classifier>
                                        <!-- Unpack the artifact in a directory at the same level than 
                                            the build directory. -->
                                        <outputDirectory>${project.build.directory}/..</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Depending on the platform I activate different profile so that I download the correct artifact (the one for Windows or the one for Linux on where our Jenkins runs. Hope it helps ! :)

    <!-- PhantomJS for Windows -->
    <profile>
        <id>phantomJS-windows</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <phantomjs.classifier>windows</phantomjs.classifier>
            <phantomjs.bin>phantomjs.exe</phantomjs.bin>
            <phantomjs.packaging>zip</phantomjs.packaging>
            <test.script.ext>bat</test.script.ext>
        </properties>
    </profile>

    <!-- XXX: Jenkins instance runs on Linux 64 bits. -->
    <!-- 64 bits. -->
    <profile>
        <id>phantomJS-bca-jenkins</id>
        <activation>
            <property>
                <name>sun.arch.data.model</name>
                <value>64</value>
            </property>
        </activation>
        <properties>
            <phantomjs.classifier>linux-x86_64</phantomjs.classifier>
            <phantomjs.bin>bin/phantomjs</phantomjs.bin>
            <phantomjs.packaging>tar.bz2</phantomjs.packaging>
            <test.script.ext>sh</test.script.ext>
        </properties>
    </profile>

Upvotes: 1

PPC-Coder
PPC-Coder

Reputation: 3632

I think your issue is the same as this one: https://github.com/klieber/phantomjs-maven-plugin/issues/34

Solution: Make sure you are using Maven 3.1 or higher.

Upvotes: 2

Related Questions