gantsign.intellij
Ansible 角色:IntelliJ
用于下载、安装和配置 IntelliJ IDEA IDE 的角色 https://www.jetbrains.com/idea。
虽然该角色可以安装 IntelliJ 插件,但如果您想有条件地安装特定插件,请查看我们的伴随角色:gantsign.intellij-plugins。
要求
Ansible Core >= 2.12
Linux 发行版
Debian 家族
Ubuntu
- Focal (20.04)
- Jammy (22.04)
RedHat 家族
Rocky Linux
- 9
注意:其他版本可能有效,但尚未测试。
Java JDK
- 需要安装 JDK 和 JDK 源代码。
- 使用 Java > 9 时,还需要安装 jmods。
例如,在 Rocky Linux 上使用 OpenJDK 17 时,需要以下配置:
- name: 安装 OpenJDK 17 become: true yum: name: - java-17-openjdk-devel - java-17-openjdk-jmods - java-17-openjdk-src state: present
Apache Maven
角色变量
以下变量会改变该角色的行为(默认值如下所示):
# IntelliJ IDEA 版本号
intellij_version: '2024.2'
# 下载 IntelliJ IDEA redistributable 包的镜像地址
# 使用 HTTP 因为 https://github.com/ansible/ansible/issues/11579
intellij_mirror: 'http://download.jetbrains.com/idea'
# 要安装的版本(社区版或最终版)
intellij_edition: community
# IntelliJ IDEA 发行版的基础安装目录
intellij_install_dir: /opt/idea/idea-{{ intellij_edition }}-{{ intellij_version }}
# 安装文件的所有者
intellij_install_user: root
# IntelliJ IDEA 项目的默认 Apache Maven 安装位置
# 默认值为 ansible_local.maven.general.home 的值(见 gantsign.maven 角色)
intellij_default_maven_home: '{{ ((((ansible_local | default(dict())).maven | default(dict())).general | default(dict())).home | default(None)) }}'
# IntelliJ IDEA 插件管理器网络服务的 URL
intellij_plugin_manager_url: 'https://plugins.jetbrains.com/pluginManager/'
# 要为 IntelliJ IDEA 配置的用户列表
users: []
# 存储 IntelliJ IDEA 安装所需下载文件的目录
intellij_download_dir: "{{ x_ansible_download_dir | default(ansible_facts.env.HOME + '/.ansible/tmp/downloads') }}"
# IntelliJ IDEA 下载响应的超时时间(秒)
intellij_idea_download_timeout_seconds: 600
用户配置如下:
users:
- username: # Unix 用户名
intellij_group: # 用户文件/目录的 Unix 组(可选 - 默认为用户名)
intellij_jdks:
- name: # 此 JDK 使用的名称
home: # JDK 的路径
# 要作为新项目的默认 JDK
# 如果您指定了 `intellij_jdks`,则为必需
# 必须与 `intellij_jdks` 中的名称匹配
intellij_default_jdk:
intellij_disabled_plugins: # 见 ~/.config/JetBrains/*Idea*/disabled_plugins.txt
- # 插件 ID
intellij_codestyles:
# 代码风格的列表(每个 XML 位置可以通过 URL 或文件系统路径指定)
- name: # 名称(必须与 XML 文件 /code_scheme/@name 中的值匹配)
url: # 下载代码风格 XML 的 URL
- name: # 名称(必须与 XML 文件 /code_scheme/@name 中的值匹配)
src: # 代码风格 XML 文件的路径(可以是绝对路径或相对路径,相对路径的评估方式与 Ansible copy 模块相同)
remote_src: # yes/no,是否从远程文件系统复制(默认为 no)
intellij_default_codestyle: # 名称(必须与 XML 文件 /code_scheme/@name 中的值匹配)
intellij_inspection_profiles:
# 检查配置文件的列表(每个 XML 位置可以通过 URL 或文件系统路径指定)
- name: # 名称(必须与 XML 文件 /profile/option[@name='myName']/@value 中的值匹配)
url: # 下载检查配置文件 XML 的 URL
- name: # 名称(必须与 XML 文件 /profile/option[@name='myName']/@value 中的值匹配)
src: # 检查配置文件 XML 文件的路径(可以是绝对路径或相对路径,相对路径的评估方式与 Ansible copy 模块相同)
remote_src: # yes/no,是否从远程文件系统复制(默认为 no)
intellij_default_inspection_profile: # 名称(必须与 XML 文件 /profile/option[@name='myName']/@value 中的值匹配)
intellij_plugins:
- # 要安装的插件的插件 ID
# 仅限最终版:Ansible 主机上 IntelliJ 许可证密钥的位置
# 您的许可证密钥可以在 ~/.config/JetBrains/*Idea*/idea.key 中找到
intellij_license_key_path: # 例如 '/vagrant/idea.key'
警告: 安装附加插件的功能依赖于 IntelliJ IDEA 内部 API,暂时应视为实验性。
支持的 IntelliJ IDEA 版本
以下版本的 IntelliJ IDEA 在没有额外配置的情况下被支持(对于其他版本,请遵循高级配置说明):
2024.2
2024.1.4
2024.1.3
2024.1.2
2024.1.1
2024.1
2023.3.6
2023.3.5
2023.3.4
2023.3.3
2023.3.2
2023.3.1
2023.3
2023.2.5
2023.2.4
2023.2.3
2023.2.2
2023.2.1
2023.2
2023.1.5
2023.1.4
2023.1.3
2023.1.2
2023.1.1
2023.1
2022.3.3
2022.3.2
2022.3.1
2022.3
2022.2.4
2022.2.3
2022.2.2
2022.2.1
2022.2
2022.1.4
2022.1.3
2022.1.2
2022.1.1
2022.1
2021.3.3
2021.3.2
2021.3.1
2021.3
2021.2.3
2021.2.2
2021.2.1
2021.2
2021.1.3
2021.1.2
2021.1.1
2021.1
2020.3.3
2020.3.2
2020.3.1
2020.3
2020.2.4
2020.2.3
2020.2.2
2020.2.1
2020.2
2020.1.2
2020.1.1
2020.1
2019.3.4
2019.3.3
2019.3.2
2019.3.1
2019.3
2019.2.4
2019.2.3
2019.2.2
2019.2.1
2019.2
2019.1.3
2019.1.2
2019.1.1
2019.1
2018.3.6
2018.3.5
2018.3.4
2018.3.3
2018.3.2
2018.3.1
2018.3
2018.2.5
2018.2.4
2018.2.3
2018.2.2
2018.2.1
2018.2
2018.1.6
2018.1.5
2018.1.4
2018.1.3
2018.1.2
2018.1.1
2018.1
2017.3.5
2017.3.4
2017.3.3
2017.3.2
2017.3.1
2017.3
2017.2.6
2017.2.5
2017.2.4
2017.2.3
2017.2.2
2017.2.1
2017.2
2017.1.5
2017.1.4
2017.1.3
2017.1.2
2017.1.1
2017.1
2016.3.5
2016.3.4
2016.3.3
2016.3.2
2016.3.1
2016.3
2016.2.5
2016.2.4
2016.2.3
2016.2.2
2016.2.1
2016.2
2016.1.3
2016.1.1
高级配置
以下角色变量依赖于 IntelliJ IDEA 版本;要使用该角色未预配置的 IntelliJ IDEA 版本,您必须配置以下变量:
# redistributable 包的 SHA256 摘要
# 即 community 版本的 ideaIC-{{ intellij_version }}.tar.gz
# 或最终版本的 ideaIU-{{ intellij_version }}.tar.gz
intellij_redis_sha256sum: d1cd3f9fd650c00ba85181da6d66b4b80b8e48ce5f4f15b5f4dc67453e96a179
IntelliJ 插件 ID
JetBrains 不会在其市场网站上公开 IntelliJ 插件 ID (https://plugins.jetbrains.com/idea)。但通过一些 JavaScript 很容易获取到 ID。
在 JetBrains Marketplace 搜索您想安装的插件并导航到其概述页面 (例如:https://plugins.jetbrains.com/plugin/12195-concise-assertj-optimizing-nitpicker-cajon-)。
在浏览器地址栏中输入
javascript:
(不要按回车)。注意:出于安全原因,您无法将
javascript:
粘贴到地址栏(浏览器不会允许您这样做),您必须手动输入。在
javascript:
后粘贴以下内容并按下回车:fetch(window.location.pathname.replace(/\/plugin\/(\d+).*/, "/api/plugins/$1")) .then((response) => response.json()) .then((data) => alert(`插件 ID: "${data.xmlId}"`));
这段代码使用正则表达式修改 URL 的路径,并利用 fetch API 向 JetBrains 插件 REST API 发起请求。然后会显示一个弹窗,显示插件 ID (
xmlId
来自 JSON 响应)。
示例剧本
最小剧本:
- hosts: servers
roles:
- role: gantsign.intellij
带有用户特定配置的剧本(默认 JDK、Maven、禁用插件和代码风格):
- hosts: servers
roles:
- role: gantsign.intellij
intellij_default_maven_home: '/opt/maven/apache-maven-3.9.4'
users:
- username: vagrant
intellij_jdks:
- name: '17'
home: '/usr/lib/jvm/java-17-openjdk-amd64'
- name: '11'
home: '/usr/lib/jvm/java-11-openjdk-amd64'
- name: '1.8'
home: '/usr/lib/jvm/java-8-openjdk-amd64'
intellij_default_jdk: '17'
intellij_disabled_plugins:
- org.jetbrains.plugins.gradle
- CVS
- com.intellij.uiDesigner
- org.jetbrains.android
- TestNG-J
- hg4idea
- Subversion
- AntSupport
- DevKit
intellij_codestyles:
- name: Example1
src: Example-style1.xml
- name: Example2
src: /example/Example-style2.xml
remote_src: true
- name: GoogleStyle
url: 'https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml'
intellij_default_codestyle: GoogleStyle
intellij_inspection_profiles:
- name: Example1
src: Example1.xml
- name: Example2
src: /example/Example2.xml
remote_src: true
- name: GantSign
url: 'https://raw.githubusercontent.com/gantsign/inspection-profile-intellij/master/GantSign.xml'
intellij_default_inspection_profile: GantSign
intellij_plugins:
- CheckStyle-IDEA
角色信息
该角色导出以下 Ansible 信息,供其他角色使用:
ansible_local.intellij.general.home
- 例如:
/opt/idea/idea-community-2024.2
- 例如:
ansible_local.intellij.general.desktop_filename
- 例如:
jetbrains-idea-ce.desktop
- 例如:
ansible_local.intellij.general.desktop_file
- 例如:
/usr/share/applications/jetbrains-idea-ce.desktop
- 例如:
ansible_local.intellij.general.user_config_dir
- 例如:
.config/JetBrains/IntelliJIdea2023.2
- 例如:
ansible_local.intellij.general.user_plugins_dir
- 例如:
.local/share/JetBrains/IntelliJIdea2023.2
- 例如:
GantSign 的更多角色
您可以在 Ansible Galaxy 找到 GantSign 的更多角色。
开发与测试
该项目使用以下工具:
提供了一个 Visual Studio Code 的 Dev Container 来开发和测试此角色。
许可证
MIT
作者信息
约翰·弗里曼
GantSign 有限公司。 公司编号:06109112(在英格兰注册)
ansible-galaxy install gantsign.intellij