我如何决定在 .gitignore 中添加 .idea/jarRepositories.xml [英] How can I decide to add .idea/jarRepositories.xml in .gitignore

查看:86
本文介绍了我如何决定在 .gitignore 中添加 .idea/jarRepositories.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac 上将 Android Studio 3.5.3 更新为 4.0.1 时发现了一个陌生文件 .idea/jarRepositories.xml.内容如下:

<项目版本=4"><组件名称=RemoteRepositoriesConfiguration"><远程存储库><选项名称=id"值=中心"/><选项名称=名称"值=Maven 中央存储库"/><选项名称=网址"值=https://repo1.maven.org/maven2";/></remote-repository><远程存储库><选项名称=id"值=jboss.community"/><选项名称=名称"value=JBoss 社区存储库"/><选项名称=网址"value=https://repository.jboss.org/nexus/content/repositories/public/"/></remote-repository><远程存储库><选项名称=id"值=BintrayJCenter"/><选项名称=名称"值=BintrayJCenter"/><选项名称=网址"值=https://jcenter.bintray.com/"/></remote-repository><远程存储库><选项名称=id"值=谷歌"/><选项名称=名称"值=谷歌"/><选项名称=网址"值=https://dl.google.com/dl/android/maven2/"/></remote-repository></组件></项目>

已经有一个

我查看了 Android Studio 4.0.0 的发行说明,发现 一段如下:

<块引用>

IntelliJ IDEA 2019.3.3

核心 Android Studio IDE 已通过 IntelliJ IDEA 到 2019.3.3 版本的改进进行更新.

要详细了解与版本 2019.3.3 累积包含的其他 IntelliJ 版本的改进,请参阅以下页面:

  • IntelliJ IDEA 2019.3
  • IntelliJ IDEA 2019.3.3

我不确定,但想知道我是否应该在 .gitignore 中添加 .idea/jarRepositories.xml 并且不应该将它提交到 git.我如何决定添加或不添加它?如果有人能澄清标准,我真的很感激.

更新:

在Android Studio 4.0.0的源码中,找到了源文件,定义了文件名jarRepositories.xml:

JpsRemoteRepositoriesConfigurationSerializer.java

public JpsRemoteRepositoriesConfigurationSerializer() {超级(jarRepositories.xml",RemoteRepositoriesConfiguration");}

RemoteRepositoriesConfiguration.java

@State(name = "RemoteRepositoriesConfiguration", storages = @Storage("jarRepositories.xml"))公共类 RemoteRepositoriesConfiguration 实现了 PersistentStateComponent{//...}

我还在 JetBrain 的 IntelliJ IDEA 社区版的存储库中找到了它们的来源.

  • 一个文档:

    <块引用>

    External Build 过程中的项目模型由 JPS(JetBrains Project System)提供.

    JPS 之前的存储库 将自己描述为:

    <块引用>

    基于 Gant 的构建框架 + dsl,具有声明式项目结构定义和自动 IntelliJ IDEA 项目构建

    解决方案

    .idea/jarRepositories.xml 文件应该添加到 .gitignore 中.它是自动生成的,只有关于 remote jar 的冗余信息存储库.

    我们的 Android 项目在项目级别的 build.gradle 中定义了这些存储库,例如:

    所有项目{存储库{谷歌()jcenter()}}

    第二个参考在其网页顶部写了以下介绍:

    <块引用>

    添加构建依赖

    Android Studio 中的 Gradle 构建系统可以轻松地将外部二进制文件或其他库模块作为依赖项包含到您的构建中....此页面描述了如何在您的 Android 项目中使用依赖项,...但请记住,您的 Android 项目必须仅使用此页面上定义的依赖项配置.[强调]

    此外,Android Studio 4.0.1 中的Add Library Dependencies 对话框有如下指令:

    <块引用>

    第一步.

    使用下面的表格查找要添加的库.此表单使用项目构建文件中指定的存储库(Google、JCenter、Android 存储库、Google 存储库)

    您可以通过以下步骤找到它:

    1. 选择文件 >Android Studio 菜单中的项目结构....
    2. 项目结构对话框的左侧菜单中选择依赖项.
    3. 模块列中选择应用.
    4. Declared Dependencies 列中选择 +.
    5. 在弹出菜单中选择1 个库依赖.

    I found an unfamiliar file .idea/jarRepositories.xml, when I updated Android Studio 3.5.3 to 4.0.1 on Mac. The content is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="4">
      <component name="RemoteRepositoriesConfiguration">
        <remote-repository>
          <option name="id" value="central" />
          <option name="name" value="Maven Central repository" />
          <option name="url" value="https://repo1.maven.org/maven2" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="jboss.community" />
          <option name="name" value="JBoss Community repository" />
          <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="BintrayJCenter" />
          <option name="name" value="BintrayJCenter" />
          <option name="url" value="https://jcenter.bintray.com/" />
        </remote-repository>
        <remote-repository>
          <option name="id" value="Google" />
          <option name="name" value="Google" />
          <option name="url" value="https://dl.google.com/dl/android/maven2/" />
        </remote-repository>
      </component>
    </project>
    

    There is already a question on it, and VonC answered that it can be added to .gitignore.

    I was wondering if I should add it in .gitignore and shouldn't commit it to git. How can I decide to add it to .gitignore?

    JetBrains.gitignore

    The popular repository gitignore of github has Android.gitignore, but it has no .idea/jarRepositories.xml at the time of writing this question.

    On the other hand, Global/JetBrains.gitignore has the following comments.

    # Gradle and Maven with auto-import
    # When using Gradle or Maven with auto-import, you should exclude module files,
    # since they will be recreated, and may cause churn.  Uncomment if using
    # auto-import.
    # .idea/artifacts
    # .idea/compiler.xml
    # .idea/jarRepositories.xml
    # .idea/modules.xml
    # .idea/*.iml
    # .idea/modules
    # *.iml
    # *.ipr
    

    As you can see, it has .idea/jarRepositories.xml and the line is commented out. It also has the following notes:

    Gradle and Maven with auto-import

    When using Gradle or Maven with auto-import, you should exclude module files, since they will be recreated, and may cause churn. Uncomment if using auto-import.

    In Android Studio 4.0.x, is it possible to use Gradle without auto-import?

    Remote Jar Repositories

    In the above Global/JetBrains.gitignore, the line # .idea/jarRepositories.xml has been added by davidkron's pull request, and he commented as follows:

    Since IntelliJ 2019.3 this file appeared automatically in our git changes. It seems these are just cached information about remote repositories that are defined in Maven/Gradle.

    Reasons for making this change:

    In a Maven/Gradle build, automatically generated files should should not be commited.

    Links to documentation supporting these rule changes:

    I haven't found a documentation or article about this file, but I'm basing my assumption on the following steps:

    • in IntelliJ the "Remote Jar Repositories" can be managed in the Settings menu
    • I deleted every entry in the list -> file disappeared
    • I re-imported the Maven/Gradle project again
    • the file appeared again with the same entries present as before

    As his comment, Android Studio 4.0.1 has Remote Jar Repositories settings, as you can see in the following screen shot.

    I checked the release notes of Android Studio 4.0.0, and found a section as follows:

    IntelliJ IDEA 2019.3.3

    The core Android Studio IDE has been updated with improvements from IntelliJ IDEA through the 2019.3.3 release.

    To learn more about the improvements from other IntelliJ versions that are included cumulatively with version 2019.3.3, see the following pages:

    • IntelliJ IDEA 2019.3
    • IntelliJ IDEA 2019.3.3

    I'm not sure but was wondering if I should add .idea/jarRepositories.xml in .gitignore and shouldn't commit it to git. How can I decide to add it or not? I really appreciate it if someone could clarify the criteria.

    Update:

    In the source code of Android Studio 4.0.0, I found source files, which define the file name jarRepositories.xml:

    JpsRemoteRepositoriesConfigurationSerializer.java

    public JpsRemoteRepositoriesConfigurationSerializer() {
      super("jarRepositories.xml", "RemoteRepositoriesConfiguration");
    }
    

    RemoteRepositoriesConfiguration.java

    @State(name = "RemoteRepositoriesConfiguration", storages = @Storage("jarRepositories.xml"))
    public class RemoteRepositoriesConfiguration implements PersistentStateComponent<RemoteRepositoriesConfiguration.State> {
      // ...
    }
    

    I also found their origins in the repository of JetBrain's IntelliJ IDEA Community Edition.

    Jps stands for JetBrains Project System, according to a document:

    The project model in External Build process is provided by JPS (JetBrains Project System).

    JPS's previous repository describes itself as:

    Gant based build framework + dsl, with declarative project structure definition and automatic IntelliJ IDEA projects build

    解决方案

    The file .idea/jarRepositories.xml should be added to .gitignore. It is auto-generated and has only redundant information about remote jar repositories.

    Our Android projects define those repositories in the project-level build.gradle such as:

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    

    The second reference wrote the following introduction at the top of its webpage:

    Add build dependencies

    The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. ... This page describes how to use dependencies with your Android project, ... but remember that your Android project must use only the dependency configurations defined on this page. [emphasis added]

    Also, Add Library Dependencies dialog in Android Studio 4.0.1 has an instruction like this:

    Step 1.

    Use the form below to find the library to add. This form uses the repositories specified in the project's build files (Google, JCenter, Android Repository, Google Repository)

    You can find it with the following steps:

    1. Select File > Project Structure... in the menu of Android Studio.
    2. Select Dependencies in the left-side menu of Project Structure dialog.
    3. Select app in the Modules column.
    4. Select + in the Declared Dependencies column.
    5. Select 1 Library Dependency in the popup menu.

    这篇关于我如何决定在 .gitignore 中添加 .idea/jarRepositories.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆