Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing artifacts does not put non-jar <type> in the dependencies block #3170

Open
Tracked by #12324
ducrohet opened this issue Oct 12, 2017 · 17 comments
Open
Tracked by #12324
Assignees
Labels
a:bug in:publishing-plugins ivy-publish maven-publish re:android Issue related to AGP
Milestone

Comments

@ducrohet
Copy link
Contributor

When publishing an artifact that has dependencies that are not jar (aar in our case), the dependency block in the pom file does not contain any type information.

The pom should looks like this:

<project ...> 
   <modelVersion>4.0.0</modelVersion> 
    <groupId>com.android.support</groupId> 
    <artifactId>leanback-v17</artifactId> 
    <version>21.0.0-rc1</version> 
    <packaging>aar</packaging> 
    <dependencies> 
       <dependency> 
         <groupId>com.android.support</groupId> 
         <artifactId>recyclerview-v7</artifactId> 
         <version>21.0.0-rc1</version> 
         <scope>compile</scope> 
         <type>aar</type>     <---- this s the part that's missing
      </dependency> 
  </dependencies> 
</project> 

<type>aar</type> is missing from the dependency section.

Note that Gradle handles this properly, but Maven does not. The fact that the dependency's own pom has <packaging>aar</packaging> does not seem to help, as I would have expected.

@liutikas
Copy link
Contributor

Could we get an update on this bug? It has been over 8 months without any response.

@marcphilipp
Copy link
Contributor

@ducrohet @liutikas Thanks for the ping! Are you using the maven plugin or the maven-publish plugin? Could you please provide a small sample project?

@liutikas
Copy link
Contributor

liutikas commented May 30, 2018

We are using maven plugin.

MavenPublish.zip

  1. Download the project
  2. Run ./gradlew uploadArchives
  3. Check path/to/project/mylib/repo/net/liutikas/myLibrary/1.0.0/myLibrary-1.0.0.pom

Observe that pom file dependencies say:

  <dependencies>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>appcompat-v7</artifactId>
      <version>27.1.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

and it is missing <type> tag even though this artifact is aar type.

@liutikas
Copy link
Contributor

liutikas commented Jun 1, 2018

Are you able to reproduce this issue?

@liutikas
Copy link
Contributor

liutikas commented Jun 4, 2018

Note this issue is also true for dependencies on projects within the same settings.gradle.

For example, if I have a project A and project B, both of them are aars and A depends on B, pom file will not have build type in the pom file.

We have to add some pretty hacky code to work around that:
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/support-library-27.1.1/buildSrc/src/main/kotlin/android/support/MavenUploadHelper.kt#99

@marcphilipp
Copy link
Contributor

@gradle/dependency-management Is the packaging from the POM of a dependency currently available in our internal data structures?

@liutikas
Copy link
Contributor

liutikas commented Jul 9, 2018

Any updates on this?

@ljacomet
Copy link
Member

@marcphilipp Yes it is available, and so is the type of a Maven dependency. And the type is properly published with both the maven and maven-publish plugins when explicit set in the dependency declaration.

This means that issue probably is about plugin interactions.

@liutikas I can't give you any timeline for getting this fixed.

@liutikas
Copy link
Contributor

@ljacomet could you point me on where the type is available of a Maven dependency? I looked at org.gradle.api.artifacts.ModuleDependency which has getArtifacts(), but sadly the set is empty unless the dependency explicitly adds the type foo:bar:1.0@aar.

hubot pushed a commit to aosp-mirror/platform_frameworks_support that referenced this issue Aug 15, 2018
To work around the bug gradle/gradle#3170
add explicit mention of dependency type @aar for android library dependencies.
This will mean that now pom files will now have correct <type>aar</type>

Comparison of old vs new:
https://paste.googleplex.com/6020163941957632

Test: ./gradlew createArchive and verify pom file dependencies now have type tag
Change-Id: Ia30454a4fba985865ea9b64622e3ba4c3ff67a3d
@mathjeff
Copy link
Contributor

Any ideas about things that we as users could do to help get this fixed sooner?

(The need for projects to specify "@aar" in dependencies seems to make it more likely for #5174 (or perhaps #7594 ) to occur)

@liutikas
Copy link
Contributor

Could we get an update on this? It would be great to have this resolved. Alternatively, it would be nice to get a response to:

@ljacomet could you point me on where the type is available of a Maven dependency? I looked at org.gradle.api.artifacts.ModuleDependency which has getArtifacts(), but sadly the set is empty unless the dependency explicitly adds the type foo:bar:1.0@aar.

@bigdaz bigdaz self-assigned this May 16, 2019
@bigdaz bigdaz added in:publishing-plugins ivy-publish maven-publish and removed in:maven-plugin labels May 23, 2019
@bigdaz bigdaz removed their assignment Jun 23, 2019
@juanchosaravia
Copy link

Any updates on this? I'm having the same issue

@jjohannes
Copy link
Contributor

jjohannes commented Oct 20, 2019

Unfortunately the issue persists. But there are some updates with Gradle 6 (RC1 available now):

  • We now fully migrated to the new mave-publish plugin. So we can think about solutions in that plugin.
  • With Gradle 6, you also publish Gradle Module Metadata, which does not suffer from this issue. So if you are only concerned about Gradle consumers the effect of the issue goes away because the dependency/module information is taken from the module and not the pom files.
  • Solving this issue in maven-publish for pom should be possible but it still requires some design decisions. The problem is that we would have to look into the dependencies to determine their packaging. But, normally, for publishing we do not even resolve the dependencies. However, you can now publish resolved versions - in that case we resolve and know the target modules, and could take the information from them. But it would be good if we find a solution that also works if you publish the declared versions. Probably as an opt-in, where we still do the resolution, but do use the original versions.

For now, I would recommend the following workaround for maven-publish:

  • Do not change anything in the dependency declarations to work around this. That could also screw up your module metadata (i.e. I would not recommend the @aar workaround anymore).
  • Instead, use withPom in your publication declaration to "fix" the necessary dependencies. E.g.:
pom.withXml {
    val dependencies = asNode().children().find { it is Node && it.name().toString().endsWith("dependencies") } as Node?
    dependencies?.children()?.forEach { dep ->
        if (dep is Node) {
            val groupId = dep.children().first { it is Node && it.name().toString().endsWith("groupId") } as Node
            val artifactId = dep.children().first { it is Node && it.name().toString().endsWith("artifactId") } as Node
            if (isAarDependency(groupId.children()[0] as String, artifactId.children()[0] as String)) {
                dep.appendNode("type", "aar")
            }
        }
    }
}

Where isAarDependency(group, name) has the knowledge if a dependency needs the aar type or not.

@ljacomet ljacomet added the @jvm label Feb 17, 2020
@ljacomet ljacomet removed the in:dependency-management DO NOT USE label Dec 2, 2020
@liutikas
Copy link
Contributor

Any updates here? It would be great to be able to resolve this issue without having to work around it. It is especially problematic now due to configuration caching, as that means you can no longer access project within pom.withXml

tonihei added a commit to google/ExoPlayer that referenced this issue Jan 4, 2022
There is an open Gradle bug that dependencies with AARs are not marked
as such in the created POM files (gradle/gradle#3170).

This causes issues building ExoPlayer with Maven POMs only.
(Issue: #8353).

This change adds the workaround suggested on the Gradle bug until
the bug is fixed. As we have a mixture of JAR and AAR dependencies,
we need to maintain a lookup table to know which dependencies have AARs.
The current code throws when a new dependency is added and it's not
classified.

#minor-release

PiperOrigin-RevId: 417797407
tonihei added a commit to androidx/media that referenced this issue Jan 5, 2022
There is an open Gradle bug that dependencies with AARs are not marked
as such in the created POM files (gradle/gradle#3170).

This causes issues building ExoPlayer with Maven POMs only.
(Issue: google/ExoPlayer#8353).

This change adds the workaround suggested on the Gradle bug until
the bug is fixed. As we have a mixture of JAR and AAR dependencies,
we need to maintain a lookup table to know which dependencies have AARs.
The current code throws when a new dependency is added and it's not
classified.

#minor-release

PiperOrigin-RevId: 417797407
@Hanmac
Copy link

Hanmac commented May 11, 2022

Any plan on fixing this after 5 years? it still causes problems with maven projects

@ljacomet ljacomet added re:android Issue related to AGP and removed in:android-support DO NOT USE labels Sep 16, 2022
@daymxn
Copy link

daymxn commented Apr 5, 2023

Friendly bump, we're still suffering from this over at Firebase :')

@jvandort
Copy link
Member

jvandort commented Aug 9, 2023

We are looking into this. In general, you should not need to resort to re-writing XML in order to publish proper component metadata (as is necessary to resolve this issue)

@jvandort jvandort self-assigned this Aug 9, 2023
@jvandort jvandort added this to the 8.5 RC1 milestone Aug 9, 2023
@jvandort jvandort modified the milestones: 8.5 RC1, 8.x Sep 4, 2023
jvandort added a commit that referenced this issue Oct 26, 2023
Use the new test fixture to verify that maven is able to resolve our published POMs
and that the classpath resolved by Maven is the same as the classpath resovled by Gradle.

We still need to work #3170 to fully support publishing to Maven
jvandort added a commit that referenced this issue Oct 26, 2023
Use the new test fixture to verify that maven is able to resolve our published POMs
and that the classpath resolved by Maven is the same as the classpath resovled by Gradle.

We still need to work #3170 to fully support publishing to Maven
@jvandort jvandort modified the milestones: 8.x, 9.x Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug in:publishing-plugins ivy-publish maven-publish re:android Issue related to AGP
Projects
None yet
Development

No branches or pull requests