【问题标题】:Converting .classpath of eclipse to gradle将eclipse的.classpath转换为gradle
【发布时间】:2016-11-01 05:45:07
【问题描述】:

我正在尝试将.classpath 转换为 gradle 项目(该项目是一个动态 Web 应用程序,使用 Spring)。我收到以下错误。

./gradlew tasks
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details

FAILURE: Build failed with an exception.

* Where:
Build file '/home/jsiddharth/workspace/feature_multiple_web_admins/mnoxwebadmin/BuseetaWebAdmin/build.gradle' line: 20

* What went wrong:
A problem occurred evaluating root project 'BuseetaWebAdmin'.
> Could not find method compile() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.838 secs

我的 .classpath 是

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/main/java">
        <attributes>
            <attribute name="FROM_GRADLE_MODEL" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/main/resources">
        <attributes>
            <attribute name="FROM_GRADLE_MODEL" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/test/java">
        <attributes>
            <attribute name="FROM_GRADLE_MODEL" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/test/resources">
        <attributes>
            <attribute name="FROM_GRADLE_MODEL" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    <classpathentry exported="true" kind="var" path="localjar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>


    .. bunch of other local jar's ..


    <classpathentry exported="true" kind="var" path="mCruiseOnLibs/json-simple-1.1.1.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="var" path="mCruiseOnLibs/javax.json-1.0.2.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry combineaccessrules="false" exported="true" kind="src" path="/localproject"/>

    .. bunch of local projects referred ..

    <classpathentry kind="output" path="bin"/>
</classpath>

Gradle 构建文件

buildscript{

    //def dropboxfolder = "/home/jsiddharth/Dropbox/mylibs"

    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        // I copied all local jar's to the libs folder that contains the build.gradle file.
        compile fileTree(dir: 'libs', include: '*.jar')

        // compile files('${dropboxfolder}/local.jar'), this did not work, so commented

        compile(project(':localproject'))
        testCompile 'junit:junit:4.12'
    }
}

apply plugin:'java'
apply plugin : 'war'

【问题讨论】:

标签: java eclipse gradle


【解决方案1】:

要构建的程序的依赖项必须在buildscript 块之外指定:

buildscript{

    //def dropboxfolder = "/home/jsiddharth/Dropbox/mylibs"

    repositories {
        jcenter()
        mavenCentral()
    }
}

apply plugin:'java'
apply plugin : 'war'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    // I copied all local jar's to the libs folder that contains the build.gradle file.
    compile fileTree(dir: 'libs', include: '*.jar')

    // compile files('${dropboxfolder}/local.jar'), this did not work, so commented

    compile(project(':localproject'))
    testCompile 'junit:junit:4.12'
}

buildscript 块内的依赖项用于构建脚本本身。

顺便说一句。所有这些都与eclipse使用的.classpath文件无关。

【讨论】:

  • repositorys 在builscript块的内部和外部
  • 我现在收到另一个错误Execution failed for task ':tasks'. &gt; Could not determine the dependencies of task ':war'
猜你喜欢
  • 2018-06-19
  • 1970-01-01
  • 2015-12-18
  • 1970-01-01
  • 2013-06-07
  • 2022-11-16
  • 2014-11-08
  • 1970-01-01
  • 2019-01-05
相关资源
最近更新 更多