org.gradle.api.Project.getConvention()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(242)

本文整理了Java中org.gradle.api.Project.getConvention()方法的一些代码示例,展示了Project.getConvention()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.getConvention()方法的具体详情如下:
包路径:org.gradle.api.Project
类名称:Project
方法名:getConvention

Project.getConvention介绍

暂无

代码示例

代码示例来源:origin: jooby-project/jooby

public JavaPluginConvention getJavaConvention(final Project project) {
 return project.getConvention().getPlugin(JavaPluginConvention.class);
}

代码示例来源:origin: uber/okbuck

@Nullable
public String getMainClass() {
 return getProject()
   .getConvention()
   .getPlugin(ApplicationPluginConvention.class)
   .getMainClassName();
}

代码示例来源:origin: uber/okbuck

public JvmTarget(
  Project project, String name, String aptConfigurationName, String testAptConfigurationName) {
 super(project, name);
 this.aptConfigurationName = aptConfigurationName;
 this.testAptConfigurationName = testAptConfigurationName;
 sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
 isKotlin =
   project.getPlugins().stream().anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper);
 Optional<Task> compileTask =
   project.getTasks().stream().filter(it -> it instanceof AbstractCompile).findFirst();
 if (compileTask.isPresent()) {
  fakeCompile = (AbstractCompile) compileTask.get();
 } else {
  fakeCompile = null;
 }
}

代码示例来源:origin: uber/okbuck

public String getMavenCoords() {
 String group = getProject().getGroup().toString();
 String id =
   getProject().getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
 String version = getProject().getVersion().toString();
 return String.join(":", group, id, version);
}

代码示例来源:origin: uber/okbuck

public String getTargetCompatibility() {
 return javaVersion(
   getProject()
     .getConvention()
     .getPlugin(JavaPluginConvention.class)
     .getTargetCompatibility());
}

代码示例来源:origin: uber/okbuck

public String getSourceCompatibility() {
 return javaVersion(
   getProject()
     .getConvention()
     .getPlugin(JavaPluginConvention.class)
     .getSourceCompatibility());
}

代码示例来源:origin: diffplug/spotless

/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */
  @Override
  protected void setupTask(SpotlessTask task) {
    if (target == null) {
      JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
      if (javaPlugin == null) {
        throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin.");
      }
      FileCollection union = getProject().files();
      for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
        union = union.plus(sourceSet.getAllSource().filter(file -> {
          String name = file.getName();
          return name.endsWith(".kt") || name.endsWith(".kts");
        }));
      }
      target = union;
    }
    super.setupTask(task);
  }
}

代码示例来源:origin: diffplug/spotless

/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */
  @Override
  protected void setupTask(SpotlessTask task) {
    if (target == null) {
      JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
      if (javaPlugin == null) {
        throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin.");
      }
      FileCollection union = getProject().files();
      for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
        union = union.plus(sourceSet.getAllSource().filter(file -> {
          String name = file.getName();
          return name.endsWith(".scala") || name.endsWith(".sc");
        }));
      }
      target = union;
    }
    super.setupTask(task);
  }
}

代码示例来源:origin: diffplug/spotless

/** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */
  @Override
  protected void setupTask(SpotlessTask task) {
    if (target == null) {
      JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
      if (javaPlugin == null) {
        throw new GradleException("You must apply the java plugin before the spotless plugin if you are using the java extension.");
      }
      FileCollection union = getProject().files();
      for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
        union = union.plus(sourceSet.getAllJava());
      }
      target = union;
    }

    steps.replaceAll(step -> {
      if (LicenseHeaderStep.name().equals(step.getName())) {
        return step.filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter());
      } else {
        return step;
      }
    });
    super.setupTask(task);
  }
}

代码示例来源:origin: diffplug/spotless

protected void setupTask(SpotlessTask task) {
  if (target == null) {
    JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class);
    if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) {
      throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension.");

代码示例来源:origin: gradle.plugin.de.otto.shopoffice/otto-classycle-plugin

private JavaPluginConvention getJavaPluginConvention(final Project project) {
  final JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class);
  if (javaPlugin == null) {
    throw new GradleException("You must apply the java plugin before the classycle plugin.");
  }
  return javaPlugin;
}

代码示例来源:origin: MinecraftForge/ForgeGradle

private SourceSet resolveSourceSet(Object obj) {
  while (obj instanceof Closure)
    obj = ((Closure<?>) obj).call();
  if (obj instanceof SourceSet)
    return (SourceSet) obj;
  else {
    String name = obj.toString();
    JavaPluginConvention javaConv = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
    return javaConv.getSourceSets().getByName(name);
  }
}

代码示例来源:origin: purplejs/purplejs

private void configureAppPlugin()
  {
    final ApplicationPluginConvention convention = this.project.getConvention().findPlugin( ApplicationPluginConvention.class );
    convention.setMainClassName( "io.purplejs.boot.MainApp" );

    final JavaExec runTask = (JavaExec) this.project.getTasks().getByName( ApplicationPlugin.TASK_RUN_NAME );
    runTask.systemProperty( "io.purplejs.runMode", "dev" );

    final String devDirs = new File( this.project.getProjectDir(), "src/main/resources" ).getAbsolutePath();
    runTask.systemProperty( "io.purplejs.devSourceDirs", devDirs );
  }
}

代码示例来源:origin: me.seeber.gradle/gradle-project-config

/**
 * Get the library directory
 *
 * @return Library directory
 */
public File getLibsDir() {
  BasePluginConvention baseConvention = this.project.getConvention().getPlugin(BasePluginConvention.class);
  File libsDir = Validate.notNull(baseConvention.getLibsDir(), "The libs dir must not be null");
  return libsDir;
}

代码示例来源:origin: mockito/shipkit

public static SourceSet getMainSourceSet(Project project) {
    final JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class);
    return java.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  }
}

代码示例来源:origin: me.seeber.gradle/gradle-project-config

/**
 * Provide the Java plugin convention
 *
 * @param project Project to get convention from
 * @return Java plugin convention
 */
@Model
@Hidden
public JavaPluginConvention javaPluginConvention(Project project) {
  return project.getConvention().getPlugin(JavaPluginConvention.class);
}

代码示例来源:origin: gradle.plugin.me.seeber.gradle/gradle-project-config

/**
 * Get the library directory
 *
 * @return Library directory
 */
public File getLibsDir() {
  BasePluginConvention baseConvention = this.project.getConvention().getPlugin(BasePluginConvention.class);
  File libsDir = Validate.notNull(baseConvention.getLibsDir(), "The libs dir must not be null");
  return libsDir;
}

代码示例来源:origin: io.github.udaychandra.susel/susel-gradle-plugin

private FileCollection getOutputClassDir(Project project) {
  return project.getConvention()
      .getPlugin(JavaPluginConvention.class)
      .getSourceSets()
      .getByName("main")
      .getOutput()
      .getClassesDirs();
}

代码示例来源:origin: dsyer/spring-boot-thin-launcher

private void configureLibPropertiesTask(PropertiesTask thin, Project project) {
  thin.setConfiguration(findRuntimeClasspath(project));
  SourceSetContainer sourceSets = project.getConvention()
      .getPlugin(JavaPluginConvention.class).getSourceSets();
  File resourcesDir = sourceSets.getByName("main").getOutput().getResourcesDir();
  thin.setOutput(new File(resourcesDir, "META-INF"));
}

代码示例来源:origin: org.gosu-lang.gosu/gradle-gosu-plugin

private void configureGosuDoc( final Project project ) {
 GosuDoc gosuDoc = project.getTasks().create(GOSUDOC_TASK_NAME, GosuDoc.class);
 gosuDoc.setDescription("Generates Gosudoc API documentation for the main source code.");
 gosuDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
 JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
 SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
 gosuDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()));
 Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
 GosuSourceSet gosuSourceSet = sourceSetConvention.getPlugin(GosuSourceSet.class);
 gosuDoc.setSource((Object) gosuSourceSet.getGosu());  // Gradle 4.0 overloads setSource; must upcast to Object for backwards compatibility
}

相关文章