phantomjs-maven-plugin:错误找不到合适的构造函数

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

我正在尝试 运行 com.github.klieber.phantomjs-maven-plugin,然后再尝试 运行 com.github.searls.jasmine-maven-插件.

最终目标是能够 运行 在 maven 中然后在 Jenkins 中测试 Javascripts。

但我总是有同样的错误:

    [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

我用

创建了一个 maven 项目
    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

这是我尝试只安装 Phantom JS 的 pom

  <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>

你能告诉我我做错了什么吗?

提前致谢,

我认为您的问题与此相同:https://github.com/klieber/phantomjs-maven-plugin/issues/34

解决方案:确保您使用的是 Maven 3.1 或更高版本。

我在 Maven 中然后在 Jenkins 中找到了 运行 Javascripts 测试的另一个解决方案

下面是我在 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>

根据平台的不同,我激活了不同的配置文件,以便我下载正确的工件(一个用于 Windows 或一个用于 Linux,在我们的 Jenkins 运行的地方。希望它有帮助!:)

    <!-- 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>