代码之家  ›  专栏  ›  技术社区  ›  Aleks G

渐变集不正确(意外?)运行任务的类路径

  •  0
  • Aleks G  · 技术社区  · 7 年前

    我的项目结构如下:

    projectRoot
      +-src
         +-main
         |   +-java
         |   |   +-package/java files go here
         |   +-resources
         |       +-config
         |           +-files go here
         +-test
             +-java
             |   +-package/java files go here
             +-resources
                 +-config
                 |   +-files go here
                 +-features
                     +-files go here
    

    在构建此项目时,它将生成以下输出结构:

    projectRoot
      +-out
          +-production
          |     +-classes
          |     |   +-package/classes in here
          |     +-resources
          |         +-config
          |             +-files in here
          +-test
                +-classes
                |   +-package/classes in here
                +-resources
                    +-config
                    |   +-files in here
                    +-features
                        +-files in here
    

    一切如预期。我定义了一个任务来运行黄瓜测试,如下所示:

    task runCucumber() {
        doLast {
            javaexec {
                main = "cucumber.api.cli.Main"
                args += ['--plugin', 'pretty', '--plugin', 'html:out/reports/cucumber/', '--plugin', 'json:out/reports/cucumber/report.json',
                         '--glue', 'com.example.mypackage.cucumber', 'classpath:features'
                         , '--tags', 'not @ignore']
                systemProperties['http.keepAlive'] = 'false'
                systemProperties['http.maxRedirects'] = '20'
                systemProperties['env'] = System.getProperty("env")
                systemProperties['envType'] = System.getProperty("envType")
                classpath = configurations.cucumber + configurations.compile + configurations.testCompile + sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
            }
        }
    }
    

    当我执行这个任务时,没有找到我的类,也没有功能。显然,这是由于类路径设置不正确。如果我用 --info 但是,我可以看到类路径是使用我指示的参数设置的,而不是 out 目录,它包含 build 目录。我希望课堂路径是:

    <all dependencies>:/projectRoot/out/production/classses:/projectRoot/out/production/resources:/projectRoot/out/test/classes:/projectRoot/out/test/resources
    

    然而,类路径包含以下内容:

    <all dependencies>:/projectRoot/build/classes/java/main:/projectRoot/build/classes/java/test:
    

    有趣的是,目录 建造 根本不是在项目根目录下生成的。如何设置类路径以便找到类和资源?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Aleks G    7 年前

    好吧,原来问题不是关于格雷德的,而是关于intellij的想法。想法是重写标准渐变路径,并将输出保存在与Gradle预期的路径不同的路径中。然后,当下一个渐变任务运行时,输出不在那里。直接使用GRADLE而不是IDEA编译解决了这个问题。

    推荐文章