2014-11-05 2 views
2

У меня есть веб-проект NetBeans, создающий файлы Java, JS и HTML. Чтобы получить возможность модифицировать JSON API, мне нужно добавить зависимость в файле build.gradle в корневой каталог проекта. Я написал файл без заголовка build.gradle, который я тестировал и правильно обрабатывал зависимости, как мне теперь изменить проект для запуска из файла build.gradle вместо ANT каждый раз и поиска через библиотеки?Преобразование проекта NetBeans на основе ANT для проекта Gradle?

ответ

1

Вам нужен build.gradle и settings.gradle файл, и вы должны удалить файл build.xml (и, возможно, nbproject/каталог)

Я рекомендую сделать Gradle проект с использованием NetBeans Gradle плагин и копирование и изменение файла build.gradle.

Затем вам необходимо добавить наборы источников в вашем build.gradle для где ваших источников - Gradle ожидает их в другом месте, чем муравей ставит NetBeans им

sourceSets { 
    main { 
    java { 
     srcDir 'src' 
    } 
    resources { 
     srcDir 'resources' 
    } 
    } 

    test { 
    java { 
     srcDir 'test' 
    } 
    resources { 
     srcDir 'testResources' 
    } 
    } 
} 

также, вам нужно сделать зависимости. Это то, что мое выглядит следующим образом:

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.10+' 
    compile project(':logger') 
    compile project(':postalker') 
    compile group: 'org.yaml', name: 'snakeyaml', version: '1.15+' 
    compile group: 'commons-io', name: 'commons-io', version: '2.4+' 
    compile group: 'gov.nist.math', name: 'jama', version: '1.0.3+' 
    compile group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-SNAPSHOT+' 
    compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.5+' 
    compile files('lib/jogl-runtime/jogl.jar') 
    compile files('lib/gluegen-runtime/gluegen-rt.jar') 
    compile files('lib/toxiclibscore.jar') 
    compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5+' 
    compile group: 'commons-codec', name: 'commons-codec', version: '1.6' 
    compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3' 
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3' 
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.6' 
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.6' 
} 

наконец, мне пришлось закрыть старый проект, закрыть NetBeans вниз, а затем вновь открыть и NetBeans проект. Сделайте проект перезагрузки, и он был запущен и запущен!

для человека, который задается вопросом, как я работал с jogl, я посмотрел, что сделал плагин jogl с муравьем и воспроизвел его с помощью градиента. Добавить PlatformPrivate.gradle файл, который содержит платформу разработчика, а затем скопировать соответствующие библиотеки в каталог сборки

вся моя build.gradle:

import com.protocase.files.FolderUtils 
import java.nio.file.Files 
import java.nio.file.Paths 
import com.protocase.designer.extractors.BuildInfoExtractor 
import com.protocase.designer.fileeditors.NSISInstallerModifier 
import com.protocase.designer.fileeditors.SignBatModifier 
import com.protocase.designer.ConfigureRun 
import com.protocase.finders.FindFiles 

apply plugin: 'java' 
apply plugin: 'application' 
apply plugin: 'groovy' 

apply from: "PlatformPrivate.gradle" 
apply from: "Platforms.gradle" 

sourceCompatibility = '1.6' 

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 

// NetBeans will automatically add "run" and "debug" tasks relying on the 
// "mainClass" property. You may however define the property prior executing 
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument. 
// 
// Note however, that you may define your own "run" and "debug" task if you 
// prefer. In this case NetBeans will not add these tasks but you may rely on 
// your own implementation. 
if (!hasProperty('mainClass')) { 
    ext.mainClass = 'com.protocase.viewer.JDesigner' 
} 

if (! hasProperty('localPlatform')) { 
    throw new GradleException("Missing PlatformPrivate.gradle"); 
} 


mainClassName = ext.mainClass 

repositories { 
    mavenCentral() 
    maven { 
      url "https://repository.apache.org/content/repositories/snapshots/" 
    } 
} 

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.10+' 
    compile project(':logger') 
    compile project(':postalker') 
    compile group: 'org.yaml', name: 'snakeyaml', version: '1.15+' 
    compile group: 'commons-io', name: 'commons-io', version: '2.4+' 
    compile group: 'gov.nist.math', name: 'jama', version: '1.0.3+' 
    compile group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-SNAPSHOT+' 
    compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.5+' 
    compile files('lib/jogl-runtime/jogl.jar') 
    compile files('lib/gluegen-runtime/gluegen-rt.jar') 
    compile files('lib/toxiclibscore.jar') 
    compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5+' 
    compile group: 'commons-codec', name: 'commons-codec', version: '1.6' 
    compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3' 
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.3' 
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.6' 
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.6' 
} 

task copyDistLibs(type: Copy) { 
    def outputDir = file("${buildDir}/libs") 

    from configurations.runtime 

    into outputDir 
} 

task updateBuildInfoBeta (type: Exec) { 
    workingDir "${projectDir}/perl" 
    commandLine './updateBuildInfo' 
    def extractor = new BuildInfoExtractor(projectFile: new File("${projectDir}")) 

    def version = extractor.getBetaVersion() 

    def installerModifier = new NSISInstallerModifier(NSISFile: new File("${projectDir}/winRunFiles/JDesigner.nsi")) 
    installerModifier.setOutputFileVersion(version) 

    def signBatModifier = new SignBatModifier(signBatFile: new File("${projectDir}/sign.bat")) 
    signBatModifier.setOutputFileVersion(version) 

    println "" 
    println "Making Beta Version: " + version 
    println "branch: " + extractor.getReleaseVersion() + " date: " + extractor.getBuildDate() 
    println "" 
} 

task makeBeta(dependsOn: updateBuildInfoBeta) { 

    def distFolderLinux64 = makeOneDistBeta("linux-amd64") 

    def ditsFolderLinux32 = makeOneDistBeta("linux-i586") 

    def distFolderWin32 = makeOneDistBeta("windows-i586") 
    FolderUtils.copyFolderContents(new File("${projectDir}/jre"), new File(distFolderWin32, "jre")) 
    FolderUtils.copyFolderContents(new File("${projectDir}/src/main/resources/library"), new File(distFolderWin32, "library")) 
    FolderUtils.copyFolderContents(new File("${projectDir}/winRunFiles"), distFolderWin32) 
    Files.copy(Paths.get("${projectDir}/license.txt"), Paths.get(new File(distFolderWin32, "license.txt").path)) 
    Files.copy(Paths.get("${projectDir}/Protocase Designer.ico"), Paths.get(new File(distFolderWin32, "Protocase Designer.ico").path)) 


    def distFolderMac = makeOneDistBeta("macosx-universal") 

} 

private File makeOneDistBeta(def nativePlatform) { 
    def plat = new com.protocase.designer.Platform(natives: nativePlatform, libFolder: 'lib', genericBuildDir: new File("${buildDir}")) 
    println plat.getNativeDistDir() 
    plat.makeAndPopulateBuildDir() 
    plat.copyLibraryFiles() 
    plat.getNativeDistDir() 

} 


makeBeta.dependsOn(jar) 
makeBeta.dependsOn(copyDistLibs) 

task makeWin32Beta(dependsOn: makeBeta, type: Exec) { 
    def wineDir = new File("${projectDir}/../../.wine/drive_c/") 
    println wineDir.exists() 
    def nsisFile = FindFiles.findFirstFileByNameWithoutDirectory(wineDir, "makensis.exe", "users") 
    println nsisFile.path 

    def MAKENSIS = nsisFile.getPath().replaceFirst("(.*)drive_c/", "c:\\\\") 
    println MAKENSIS 
    MAKENSIS = MAKENSIS.replaceAll("/","\\\\") 

    def extractor = new BuildInfoExtractor(projectFile: new File("${projectDir}")) 
    def version = extractor.getBetaVersion() 

    workingDir "${buildDir}/windows-i586" 


    def fullCommand = 'WINEDEBUG=fixme-win,fixme-sync,fixme-heap /usr/bin/wine "' + MAKENSIS + '" /V1 /DVER_STR=' + version + ' /X"SetCompressor /FINAL lzma" ./JDesigner.nsi' 

    println "makensis command:" 
    println MAKENSIS 
    println fullCommand 
    println "" 

    commandLine fullCommand 
} 



private void configureRun (def task) { 
    apply from: 'PlatformPrivate.gradle' 
    def confRun = new ConfigureRun(localPlatform: localPlatform) 

    confRun.configureRun(task, mainClass, sourceSets) 
} 

run { 
    configureRun(it) 
} 

task(debug, dependsOn: 'classes', type: JavaExec) { 
    configureRun(it) 
    debug = true 
} 

PlatformPrivate.gradle

ext { 
    localPlatform='linux-amd64' 
} 

com.protocase.designer.Platform:

package com.protocase.designer 

import com.protocase.files.FolderUtils 
import org.gradle.api.GradleException 
import static groovy.io.FileType.FILES 
import java.nio.file.StandardCopyOption 
import java.io.File 
import java.nio.file.Files 
import java.nio.file.Paths 

public class Platform { 
    def natives 
    def libFolder 
    def genericBuildDir 

    String gluegenDir() { 
    def dirName = 'gluegen-rt.jar-natives-' + natives 
    dirName 
    } 

    String joglDir() { 
    def dirName = "jogl.jar-natives-" + natives 
    dirName 
    } 

    def getExtension() { 
    def result = "" 
    switch (natives) 
    { 
     case 'linux-amd64': 
     case 'linux-i586': 
     case 'solaris-i586': 
     case 'solaris-sparc': 
     case 'solaris-sparcv9': 
     result = 'so' 
     break; 

     case 'macosx-universal': 
     case 'macosx-ppc': 
     result = 'jnilib' 
     break; 

     case 'windows-i586': 
     case 'windows-amd64': 
     result = 'dll' 
     break; 

     default: 
     throw new GradleException ('programmer missed a case or bad platform: ' + natives) 
    } 

    result 
    } 

    def getNativeDistDir() { 
    def buildDir = new File(genericBuildDir, natives) 
    } 

    def makeAndPopulateBuildDir() { 
    def sourceDir = new File(genericBuildDir, 'libs') 
    def nativeDistDir = getNativeDistDir() 

    if (nativeDistDir.exists()) { 
     FolderUtils.deleteFolder(nativeDistDir) 
    } 

    FolderUtils.copyFolderContents(sourceDir, nativeDistDir) 
    } 

    def getLibraryDirs() { 
    def dirList = [] 

    def dir = new File(new File(libFolder, "gluegen-runtime"), gluegenDir()) 

    dirList << dir 

    dir = new File(new File(libFolder, "jogl-runtime"), joglDir()) 

    dirList << dir 

    dirList 
    } 

    def getLibraryFiles() { 
    def fileList = [] 

    def dirs = getLibraryDirs() 

    dirs.each { 
     it.eachFile(FILES) { 
    file -> fileList << file 
     } 
    } 

    fileList 
    } 

    def copyLibraryFiles() { 

    def copyOptions = [StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES] 
    def destinationFolder = new File(getNativeDistDir(), 'lib') 

    getLibraryDirs().each { 
     FolderUtils.copyFolderContents(it, destinationFolder) 
    } 
    } 

} 
+0

Привет, У меня проблемы с запуском jogl и град, работающий вместе, я вижу в ваших «зависимостях» вы его используете ... не возражаете ли вы показать полный 'build.gradle'? – elect

+1

Я добавил свой полный build.gradle и пару других файлов gradle, которые я сделал. Если я что-нибудь пропустил, дайте мне знать. – vextorspace

+0

Большое спасибо, человек! Я буду копать его в следующие дни .. – elect

Смежные вопросы