歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Intellij IDEA 插件開發之自建插件倉庫

Intellij IDEA 插件開發之自建插件倉庫

日期:2017/2/28 13:44:02   编辑:Linux教程

Intellij IDEA 有一個自己的官方的插件倉庫,但是當我們的開發的 Intellij IDEA 的插件不能夠對外公開時,我們就需要搭建自己的 Intellij IDEA 的插件倉庫。前不久我們也嘗試著使用Intellij IDEA自己開發一個插件點擊打開鏈接。

搭建 Intellij IDEA 插件倉庫

Intellij IDEA 的官方文檔裡面有提到怎麼去新建一個插件倉庫,但是,這部分的文檔卻不在 Intellij IDEA 插件的開發文檔裡面,而是在插件相關功能的使用文檔裡面: https://www.jetbrains.com/help/idea/2016.3/adding-plugins-to-enterprise-repositories.html

這裡簡單對這個文檔進行一個說明,如果需要新建一個插件倉庫,非常簡單,只需要提供一個 URL,當訪問這個 URL 的時候,返回如下的一個 XML 即可:

<plugins>
    <plugin id="com.taobao.middleware.HotCode2Plugin" url="http://localhost/downloads/hotcode2-idea-plugin.jar" version="0.1"/>
    <plugin id="com.alipay.sofa.andromeda" url="http://localhost/idea/download/com.alipay.sofa.andromeda-1.1.34.zip" version="1.1.34"/>
</plugins>
注:
  • id 為插件的 ID,需要跟在插件的 plugin.xml 裡面的設定的 ID 一致。
  • url 為插件的 ZIP 包下載的地址。
  • version 是插件的版本號。

使用 gradle 來構建 intellij IDEA插件

添加 Intellij PluginGradle 的支持其實和 Android 差不多, 需要添加官方的插件支持.

1, 在你 Intellij plugin 項目的根目錄裡執行命令 gradle init 來初始化一個 gradle 工程。

2, 修改 build.gradle 文件,讓它能夠支持構建 intellij 插件。

3, 添加 intellij build plugins 倉庫地址: https://plugins.gradle.org/plugin/org.jetbrains.intellij 官方推薦了兩種添加方式, 這裡我們采用第二種。

plugins {
  id "org.jetbrains.intellij" version "0.1.10"
}
4, 使用 intellij idea 的插件(這和Android添加插件是一樣的)
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'

5, 設置運行插件的 intellij 版本以及沙箱地址

intellij {
    version = 'IU-163.7342.3' //調試我們插件的版本
    sandboxDirectory = project.rootDir.canonicalPath + "/.sandbox" //插件生成的臨時文件的地址
}
完成以上操作, 我們需要用 Idea 來重新以 gradle 的工程來導入我們的項目,這樣就可以支持 gradle 啦。

附上build.gradle的完整配置:

/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'darin' at '11/4/16 10:39 AM' with Gradle 2.12
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.12/userguide/tutorial_java_projects.html
 */


plugins {
    id 'org.jetbrains.intellij' version "0.1.10"
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'


// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()

    maven {
        url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
    }
}

intellij {
    version = 'IU-163.7342.3'
    plugins = ['JavaScriptLanguage', 'CSS']
    sandboxDirectory = project.rootDir.canonicalPath + "/.sandbox"
}

sourceSets {
    main.java.srcDirs = ['src', 'gen']
    main.resources.srcDir 'resources'

    test.java.srcDir 'test/src'
    test.resources.srcDir 'test/data'
}

// In this section you declare the dependencies for your production and test code
dependencies {
    compile fileTree(dir: 'lib', include: ['*.jar'])
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.18'

    // Declare the dependency for your favourite test framework you want to use in your tests.
    // TestNG is also supported by the Gradle Test task. Just change the
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
    // 'test.useTestNG()' to your build script.
    testCompile 'junit:junit:4.12'

    compile 'com.google.zxing:core:3.2.1'
    compile 'com.google.zxing:javase:2.2'
}

使用 Gradle 來快速發布插件到自建倉庫

Jetbrains 官方提供了一個 Gradle Intellij Plugin 來幫助我們構建發布 Intellij IDEA 插件。 對於發布 Intellij IDEA 插件的支持,默認行為是發布到 Jetbrains 的官方的倉庫上面去的,不過在最新的 SNAPSHOT 版本中,這個插件提供了一個屬性 host 可以設置自定義的倉庫,我們可以在自己的 build.gradle 文件裡面設置這個 host 屬性:

publishPlugin.doFirst {
     publishPlugin.host = 'http://ysera.alipay.net:9000/'
 }
設置好了之後,就可以直接使用 gradle publishPlugin 來發布 Intellij IDEA 插件了。不過這裡需要注意,我們上傳的插件需要包含如下信息:
  • userName :用戶名
  • password :密碼
  • xmlId :插件的 ID,也就是在 plugin.xml 裡面定義的 ID。
  • file :插件的 ZIP 包。

所以到這裡,我們自建的插件倉庫就可以使用了。

使用IntelliJ IDEA 13搭建Android集成開發環境圖文教程 http://www.linuxidc.com/Linux/2015-09/123416.htm

IntelliJ IDEA 12 創建Web項目圖文詳細教程 http://www.linuxidc.com/Linux/2013-05/84213.htm

用IntelliJ IDEA開發Android程序圖文教程 http://www.linuxidc.com/Linux/2013-03/81471.htm

IntelliJ IDEA 12開發haXe NME應用配置指南 http://www.linuxidc.com/Linux/2013-01/77227.htm

IntelliJ IDEA運行Play Framework的test mode http://www.linuxidc.com/Linux/2013-07/87694.htm

Ubuntu 13.04 安裝IntelliJ IDEA 12 http://www.linuxidc.com/Linux/2013-11/93014.htm

IntelliJ IDEA 12創建Maven管理的Java Web項目(圖解) http://www.linuxidc.com/Linux/2014-04/99687p2.htm

IntelliJ IDEA 常用快捷鍵列表及技巧大全 http://www.linuxidc.com/Linux/2015-04/116398.htm

在 Ubuntu Linux 上安裝 IntelliJ IDEA http://www.linuxidc.com/Linux/2016-12/137946.htm

IntelliJ IDEA 的詳細介紹:請點這裡
IntelliJ IDEA 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved